Home  >  Article  >  WeChat Applet  >  How to transpose a two-dimensional array horizontally and vertically in JS

How to transpose a two-dimensional array horizontally and vertically in JS

不言
不言Original
2018-06-27 15:55:442477browse

Below I will share with you a JS method for transposing two-dimensional arrays horizontally and vertically. It has a good reference value and I hope it will be helpful to everyone. Let’s take a look together

I want to rotate a two-dimensional array horizontally and vertically. I don’t believe I am the only one who has this need, but I have searched on Baidu for a long time and searched all over the world...

Later it turned out that Google is still easy to use as the master said~ The first one is, despise Baidu

This record is recorded for the convenience of all Taoist friends (I really want to say "Fellow Immortal" ", the sequelae of being poisoned by a drama recently~~~)

##

  var newArray = arr[0].map(function(col, i) {
    return arr.map(function(row) {
    return row[i];
    })
  });

The above is the entire content of this article, I hope It will be helpful for everyone’s learning. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

How to get data in javascript from WeChat applet

About passing array parameters from js to the background controller Methods

The above is the detailed content of How to transpose a two-dimensional array horizontally and vertically in JS. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn