My goal is to compare 2 objects if there is a match between object 1 and 2 using if they have the same id then insert new key value to object 1 which isConfirmed = true to each object that has a match;
Any idea guys ? I provided my current code below. Thanks.
#objects - original data
const object1 = [
{
"id": 10691,
"city": "Morris",
},
{
"id": 10692,
"city": "NY",
]
const object2 = [
{
"id": 10691,
"city": "Morris",
{
"id": 10500,
"city": "JY",
}
]
#ts code
let result = object1.filter(o1 => object2.some(o2 => o1.id === o2.id));
#expected sample result
object1 = [
{
"id": 10691,
"city": "Morris",
"isConfirmed": true,
},
{
"id": 10692,
"city": "NY",
}
]