JavaScript two-dimensional array rectangle inverted (only for rectangles)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.