[[1,3,5], [2,4,6]]; processed into [[1,2], [3,4], [5,6]]

Requirements encountered today: array [[1,3,5], [2,4,6]]; processed into [[1,2], [3,4], [5,6]]

   let newAry = [];
   let  arr = [[1,3,5],[2,4,6]]
   for (let i = 0; i<arr.length; i++){
       for (let j = 0; j <arr[i].length; j++){
           newAry[j] = newAry[j]  || [];
           newAry[j].push(arr[i][j])
       }
   }
   console.log(newAry);

 

Guess you like

Origin www.cnblogs.com/0520euv/p/12620868.html