We have 2 arrays containing data for objects with same key values
arr1 = [
{"id": "qwerty1234",
"color": "red"},
...
]
arr2 = [
{"id": "qwerty1234",
"price": 123},
....
]
I would like to iterate through all arr1 id values while I find the matching objects from another array arr2. I've been trying with this:
const merge = (array1, array2) => {
array1.forEach(itm => {
const a = array2.find(item => (item.id === itm.id))
console.log(a.id)
})
}
This ---console.log--- causes undefined
I think my itm.id causes the problem somehow. The comparison in find() fails even though I get right values from forEach().
In the end we could consider merging these 2 arrays by their id values.
Any ideas?