js- initial array is a two-dimensional array of 4 rows 3. Convert it to a two-dimensional array of four rows and three columns

The initial array is a two-dimensional, three rows of four arrays. Convert it to a two-dimensional array of four rows and three columns

let arr = [[2,3,6,8],[5,7,0,9],[1,3,5,7] ];
let str = [];

for(let i = 0;i<arr[0].length;i++){
   str[i] = [];
}
console.log(str)
for(let j =0;j<arr.length;j++){
    for(let k =0;k<arr[j].length;k++){
        str[k][j]=arr[j][k];
    }
}
console.log(str);

 

Guess you like

Origin www.cnblogs.com/gao7/p/11119132.html