I need to combine the array results in js based on the header names. The number of arrays passed for processing is not known and it can vary from 2 to 30 plus arrays and the final expected result is a combination of column data based on header names.
The input array column orders may be shuffled as shown below
array1 = [
["A","B","C"], // headers
["AA1","BB1","CC1"],
["AAA1","BBB1","CCC1"], ...
]
array2 = [
["B","C","A", "D"], //headers
["BB2","CC2","AA2", "DD2"],
["BBB2","CCC2","AAA2","DDD2"],...
]
...
arrayn = [
["A","C","B", ...], //headers
["AAn","CCn","BBn", ...],
["AAAn","CCC2","BBBn", ...],...
]
result =
[
["A","B","C", "D"],
["AA1","BB1","CC1",""],
["AAA1","BBB1","CCC1",""],
["AA2","BB2","CC2","DD2"],
["AAA2","BBB2","CCC2,"DDD2"],
...
["AAn","BBn","CCn",...],
["AAAn","BBBn","CCCn,...],
]
I have tried with
for(var i=0;i<array1;i++)
{
for(var j=0;j<array2;j++)
{
if(array1[i][j]==array2[0][j])
{
result.push(array[i][j])
}
}
}
UDPATE: The number of columns may vary from input array, but they all would appear in the result. Like array2 has D column and the result would have DD2 and DDD2