我有两个数组,一个数组具有m个维度的mArr,另一个数组具有n个维度的nArr,我想在末尾附加较小的mArr到较大的nArr。
mArr = [[NewH], [DD1], [DD2], [DD3], [44]]
nArr = [[Id, H1, H2, H3], [1.0, aa1, bb1, cc1], [2.0, aa2, bb2, cc2], [3.0, aa3, bb3, cc3], [4.0, aa4, bb4, cc4]]
我需要
result = [[Id, H1, H2, H3, NewH], [1.0, aa1, bb1, cc1, DD1], [2.0, aa2, bb2, cc2, DD2], [3.0, aa3, bb3, cc3, DD3], [4.0, aa4, bb4, cc4, DD4]]
我尝试过的一些事情:
values = transpose([mArr,nArr])
and
if ( mArr.length > 0 ) {
var i = 0;
while ( i < mArr.length ) {
nArr.push(mArr[i]);
i++;
}
}
我猜这些仅适用于相同维数组
谢谢
答案 0 :(得分:3)
您可以使用Array.map完成此操作
nArr.map(function(row, i){
return row.concat(mArr[i]);
})
mArr = [[1],[2]];
nArr = [[4,5], [5,6]]
result=nArr.map(function(row, i){
return row.concat(mArr[i]);
})
console.info(result);