Reverse order of Multidimensional Array

2

I need to invert the positions of an Array, where the first pass to the last the second to the penultimate and so on.

For example, I have a 3-position Array:

[1,1.00,2300]
[2,1.00,4500]
[3,1.00,2340]

and this should be your result:

[3,1.00,2340]
[2,1.00,4500]
[1,1.00,2300]

Thanks !!!

    
asked by Kevin A 08.05.2018 в 08:13
source

1 answer

1

There are different ways to modify the order of an array as sort() (sort alphabetically or numerically [ modifying it a little], ascending or descending) , reverse() (reverses the order of an array by sending the first position to the last and so on) , ...

REVERSE

Summary

The reverse() method reverses (inversely) a matrix. The first element becomes the last and the last becomes the first.

Syntax

  

arr.reverse ()

Description

The reverse method crosses the elements of the parent object invoked instead, by mutating the array, and returning a reference to it.

Examples

The following example creates a matrix myMatrix, contains three elements, these are placed upside down (inversely) in the matrix.

var miMatriz = [[1,1.00,2300],[2,1.00,4500],[3,1.00,2340]];
var invertida = miMatriz.reverse(); 

console.log(miMatriz); 
console.log(invertida);
    
answered by 08.05.2018 в 09:05