期待效果:
核心代码:
//js
function handle(array) {var result = [];for (let i = 0; i < array[0].length; i++) {var item = []; for (let j = 0; j < array.length; j++) {item.push(array[j][i])} result.push(item);} return result;
}
运行代码:
let arr = [['a1', 'b1', 'c1'],['a2', 'b2', 'c2'],['a3', 'b3', 'c3'],
];
function handle(array) {var result = [];for (let i = 0; i < array[0].length; i++) {var item = [];for (let j = 0; j < array.length; j++) {item.push(array[j][i]);}result.push(item);}return result;
}
console.log("数组>>>", arr);
console.log("按列循环二维数组>>>", handle(arr));
控制台运行效果: