If I have two arrays of objects structured like this:
var arr1 = [{name: 'Jay'}, {name: 'Bob'}];
var arr2 = [{age: 22}, {age: 30}];
I am looking to merge them into a combined array as follows:
var arr3 = [{name: 'jay', age: 22}, {name: 'Bob', age: 30}];
It can be assumed that the indexes of the two initial arrays match each other, so index 0 of arr1 pairs with index 0 of arr2 consistently.
What is the most efficient method to achieve this? One possible approach could involve iterating over each array using nested forEach
loops to combine objects from arr1
with their corresponding objects from arr2
, but this may be overly complex.