let arr3 = 123123213433243俩种方式遍历二维数组
有两种方式可以遍历二维数组。
方式一:使用嵌套的for循环遍历
for(let i=0; i<arr3.length; i++){
for(let j=0; j<arr3[i].length; j++){
console.log(arr3[i][j]);
}
}
方式二:使用forEach方法遍历
arr3.forEach(function(innerArray){
innerArray.forEach(function(element){
console.log(element);
})
});
这两种方式都可以将二维数组的每个元素输出到控制台。
原文地址: https://www.cveoy.top/t/topic/in4O 著作权归作者所有。请勿转载和采集!