650) this.width=650; "id=" image_operate_4931440647637541 "src=" http://s10.sinaimg.cn/mw690/005v5x0Lzy6UXskdgz7d9 &690 "alt=" 005v5x0lzy6uxskdgz7d9&690 "/>
You want to invert the two-dimensional array of this rectangular arrangement.
Reach
9 8 2
0 9 4
2 0 6
1-1 8
The effect,
Idea: A top-down traversal of a rectangle, i.e. 9 8 2 0 9 4 2 0 6 1-1 8
Traverse thinking: arr.length=3;arr[0].leng=4; to arr.length=3; Traverse for the main for loop
Code
1. var arr1=[[2,4,6,8],[8,9,0,-1],[9,0,2,1]];//array 2. for (Var i=0;i<arr1.length;i++) {//Traversal 3 for the first time. for (Var j=0;j<arr1[i].length;j++) {4. Document.writeln ("arr1[i][j]+"); 5. } 6. Document.writeln ("<br/>"); 7. }
The results are now output
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/72/2D/wKioL1Xej2vyLVKiAAAhHtaCeD4820.jpg "title=" 360 Feedback 16490129145415.png "alt=" Wkiol1xej2vylvkiaaahhtaced4820.jpg "/>
And then upside down.
8. for (Var x=0;x<arr1[0].length;x++) {9. for (Var y=arr1.length-1;y>=0;y--) {10. Document.writeln ("arr1[y][x]+"); 11. }12. Document.writeln ("<br/>"); 13. }
Output: Inverted success. Only for rectangles
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/72/30/wKiom1XejffhedX4AAEHwVx-EQ4635.jpg "title=" 360 Feedback 16331204131836.png "alt=" Wkiom1xejffhedx4aaehwvx-eq4635.jpg "/>
This article is from the "9953079" blog, please be sure to keep this source http://9963079.blog.51cto.com/9953079/1688805
JavaScript two-dimensional array rectangle is inverted (only for rectangles)