update array of object using other array javascript 1

update array of object using other array javascript

arra1 = arra1.map(item => {
  let item2 = arra2.find(i2 => i2.transid === item.transid);
  return item2 ? { ...item, ...item2 } : item;
});

Here is what the above code is Doing:
1. It’s taking the first array and mapping over it.
2. For each item in the first array, it’s finding the corresponding item in the second array.
3. If it finds the corresponding item, it’s merging the two items into a new object.
4. If it doesn’t find the corresponding item, it’s returning the first item.

Similar Posts