Skip to content
Advertisement

Match two arrays with same id

JavaScript

How to push name from array1 to array2 with matching ids

end result

JavaScript

Advertisement

Answer

Here’s how I’d do it:

JavaScript

i.e. create an object out of one of the arrays, using the id as the key. Then you can map over the 2nd one and use the ‘index’ to quickly look up elements in the first one.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement