For example, I have two array object with different column names and values and I want them to be at same index
let a = [{name: 'asha', age:20, mother: "sushi", father: "Nick"}]
let b = [{class: "10th", Sub: "science", Marks: 30}]
and I want to merge these into a single array like this:
[{name: 'asha', age:20, mother: "sushi", father: "Nick", class: "10th", Sub: "science"}]
3
Answers
You can use
Array#map
to combine elements at the same index with spread syntax.Assuming both arrays have the same length, you can use a for loop with the spread operator on corresponding elements
You can use
Array#forEach
as follows: