I'm trying to Merge two arrays in a array using JavaScript but I'm not getting the exact output using concat method. Can any one help me?
var a1= [[0, 1],[1, 5],[2,5],[3,7]];
var a2= [[1,9],[0,6],[3,8],[2,6]];
//output
var result=[[0,1,6],[1,5,9],[2,5,6],[3,7,8]];
for example for every array in a1 find the corresponding (the elements at index zero match) array in a2 and merge the elements
code which I have retied
var v1 = [[0, 1],[1, 5],[2,5]];
var v2 = [[0,5],[1,6],[2,8]];
const res = v1.map((x, i) => [...new Set([...x, ...v2[i]])]);
console.log(res);
concat()?a1find the corresponding (the elements at index zero match) array ina2and merge the elements