Looking for a more efficient solution to retrieve data from a collection in Typescript. The data is structured as follows:
myData:
{
Id: string,
Name: string,
Address: string
Salary: number
phone: number
}
We have approximately 500 records, each with a unique ID. These records are displayed in a table showing only the ID and Name with checkboxes for each row.
When certain checkboxes are selected, I need to retrieve corresponding data by iterating through the list and taking action.
var selected: ImyData[];
for(var d in data)
{
if(d.id == myId)
{
this.selected.id = d.id;
this.selected.address = d.address
this.selected.salary = d.salary
return;
}
}
The current approach checks every element in the collection, which is not performance-effective. Any suggestions on how to improve efficiency in Typescript?