This article describes the method of transpose javascript two-dimensional arrays. Share it for your reference. The specific implementation method is as follows:
Copy the code as follows:<script language="javascript" type="text/javascript">
var arr1 = [[30,-1,90],[70,100,-40],[39,29,6],[39,92,9]];
var arr2 = [];
//Determine how many rows there are in the new array
for(var i=0;i<arr1[0].length;i++){
arr2[i] = [];
}
// Dynamically add data
//Transfer the original array
for(var i=0;i<arr1.length;i++){
for(var j=0;j<arr1[i].length;j++){
arr2[j][i] = arr1[i][j];
}
}
//Print new array
for(var i=0;i<arr2.length;i++){
for(var j=0;j<arr2[i].length;j++){
document.writeln(arr2[i][j]);
}
document.write("<br />");
}
</script>
I hope this article will be helpful to everyone's JavaScript programming.