微信小程序 push二维数组

pushdArray: function(arr, index, value) { if(index >= arr.length) { return; } arr[index].push(value);
return arr; },

var tArr = [[1,2,3],["a","b","c"],["A","B","C"]]; ; console.log(JSON.stringify(pushdArray(tArr, 0, 123))); //[[1,2,3,123],["a","b","c"],["A","B","C"]]


【微信小程序 push二维数组】 遍历循环插入不同值,就加个循环,没传的值就不push。逻辑视业务而定
function pushdArray(arr, valueArr) { if(valueArr.length) { for(var i = 0; i < arr.length; i++) { if(valueArr[i]) { arr[i].push(valueArr[i]); } } } return arr; }var tArr = [[1,2,3],["a","b","c"],["A","B","C"]]; var vArr = [4,'d','D']; console.log(JSON.stringify(pushdArray(tArr, vArr))); //[[1,2,3,4],["a","b","c","d"],["A","B","C","D"]]


    推荐阅读