Question: I have a array like this:

```
var test = [
             [1,1,1],
             [0,1,1],
             [0,0,0],
             [0,0,0]
           ];

```

I'm wondering how to it from the bottom like this:

```
var test = [
             [0,0,0,1],
             [0,0,1,1],
             [0,0,1,1]
           ];

```

I've tried this example

```
var ReverseArray = [];
var length = test.length;
for(var i = length-1;i>=0;i--){
   ReverseArray.push(test[i]);
}

```

But I got this:

```
[
  [0,0,0],
  [0,0,0],
  [0,1,1],
  [1,1,1]
];

```

It's not what I'm looking for. Anybody have good suggestions? Thx :)

Answer: 
The code you've shown actually does *reverse* the input, but your desired output is a *rotation*, not a reversal.

Here's one way to do that with one line of code:

```js
var test = [
             [1,1,1],
             [0,1,1],
             [0,0,0],
             [0,0,0]
           ];

var output = test[0].map((_,i) => test.map(a => a[i]).reverse());

console.log(output);
```

Or the same thing without [arrow functions](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/Arrow_functions) (in case you're using IE), formatted in a way that probably makes it a bit easier to follow:

```
var output = test[0].map(function(_,i) {
  return test.map(function(a) { return a[i] }).reverse();
});

```

That assumes that the outer array will have at least one entry and that all inner arrays are of the same length.

(Edit) Note that using plain loops would be more efficient, because you could loop backwards rather than having to call `.reverse()`.
Unfortunately, I don't think there are any nifty javascript tricks for rotating a matrix, but the below is still a pretty clean way to do it:

```
let cols = [], reversed = test.reverse();
for(let i = 0; i < reversed[0].length; i++)
    cols.push(reversed.map(row=> row[i]));

```

`cols` should be a matrix in the desired configuration. [demo](https://jsfiddle.net/xurbhfrs/1/)