Reputation: 4189
Im trying to find a "item" object which has updated values, based on another "item" object (visItem) in this case.
then I want to overwrite the "visItem" with the found and updated "item"
I have tried to base it on something like the link below, but im not sure how to implement it in my scenario. Searching and then overwriting the outdated object.
Here is some pictures to set the scene.
update section containing the wanted item
Upvotes: 0
Views: 314
Reputation: 767
So you want to iterate through the items array, and find an object where the grpid and id match?
if so, you could do a simple search:
for(i=0; i<items.length; i++) {
if(items[i].grpid === visItem.grpid && items[i].id === visItem.id) {
//Match found
visItem = items[i]; //Overwrites visItem with the found item
break;
}
}
Upvotes: 2
Reputation: 3451
Check the FindIndex , with using this you can find index in the array of the object and replace it with your data.
var item = {YOUR UPDATED ITEM}
var items = [YOUR ARRAY OF ITEMS];
var getIndex= items.findIndex(x => x.id == item.id);
items[getIndex] = item;
Upvotes: 2