// 需求: 根据 [[1,2],[11,22],[111,222]] 得到 [[1,11,111],[2,22,222]] function getData(list) { let result = new Array(list[0].length).fill([]) list.forEach((item, index) => { item.forEach((cItem, cIndex) => { result[cIndex] = [...result[cIndex], cItem] }) }) return result } // 原数组: let list = [ [1, 2, 3, 4, 5, 6], [11, 22, 33, 44, 55, 66], [111, 222, 333, 444, 555, 666] ] getData(list) // [ // [1, 11, 111], // [2, 22, 222], // [3, 33, 333], // [4, 44, 444], // [5, 55, 555], // [6, 66, 666] // ] // 同理,转回去也用同样的方法: const test = getData(list) getData(test) // [ // [1, 2, 3, 4, 5, 6], // [11, 22, 33, 44, 55, 66], // [111, 222, 333, 444, 555, 666] // ]
标签:11,数组,22,list,二维,111,result,互换,222 From: https://www.cnblogs.com/wiliam/p/16776359.html