其他分享
首页 > 其他分享> > 记录数组问题

记录数组问题

作者:互联网

数组遍历问题 

var _TheArray = [{"data":["0-1","0-2","0-3"],id:"111"},{"data":["1-1"],id:"222"},{"data":["2-1","2-2"],id:"333"},{"data":["3-1","3-2"],id:"444"}]; 

var dataMaxLength = 0;

for(var n in _TheArray){

         if(_TheArray[n].data.length > dataMaxLength ){

                   dataMaxLength =_TheArray[n].data.length;

         }

}

console.log("dataMaxLength :"+dataMaxLength );

if(dataMaxLength > 0){

    for(var j=0;j < dataMaxLength;j++){ 

        for(var k=0;k<_TheArray.length;k++){ 

        if(_TheArray[k].data[j] != undefined){//防止data长度层次不齐

                console.log(_TheArray[k].data[j]);

            }

        }

}    }

 

复习 二维数组的建立 和增加元素

var _TheArray = [{"data":["0-1","0-2","0-3"],id:"111"},{"data":["1-1"],id:"222"},{"data":["2-1","2-2"],id:"333"},{"data":["3-1","3-2"],id:"444"}];

var _TheArrayTwo = new Array();

_TheArrayTwo[0] = _TheArray;_TheArrayTwo.push(_TheArray);

_TheArrayTwo

标签:记录,问题,var,TheArrayTwo,数组,TheArray,dataMaxLength,data,id
来源: https://www.cnblogs.com/tldxh/p/12481964.html