Array.prototype.reverse()
Il metodo reverse()
inverte ua matrice (array) sul posto. Il primo elemento di matrice diventa l'ultima, e l'ultimo elemento di matrice diventa il primo.
var a = ['one', 'two', 'three'];
a.reverse();
console.log(a); // ['three', 'two', 'one']
Sintassi
a.reverse()
Valore prodotto.
La matrice invertita.
Descrizione
Il metodo reverse traspone gli elementi della matrice chiamata, mutando la matrice, e restituendo un riferimento alla matrice.
Esempi
Inversione degli elementi nella matrice
L'esempio seguente crea una matrice a, contenente tre elementi, quindi inverte la matrice. La chiamata ad invertire () restituisce un riferimento alla matrice invertita a.
var a = ['one', 'two', 'three'];
var reversed = a.reverse();
console.log(a); // ['three', 'two', 'one']
console.log(reversed); // ['three', 'two', 'one']
Specifiche
Specifica | Status | Commento |
---|---|---|
ECMAScript 1st Edition (ECMA-262) | Standard | definizione iniziale. Implementata in JavaScript 1.1. |
ECMAScript 5.1 (ECMA-262) The definition of 'Array.prototype.reverse' in that specification. |
Standard | |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Array.prototype.reverse' in that specification. |
Standard | |
ECMAScript (ECMA-262) The definition of 'Array.prototype.reverse' in that specification. |
Living Standard |
Compatibilità browser
We're converting our compatibility data into a machine-readable JSON format.
This compatibility table still uses the old format,
because we haven't yet converted the data it contains.
Find out how you can help! (en-US)
Caratteristica | Chrome | Firefox (Gecko) | Edge | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Supporto base | 1.0 | 1.0 (1.7 or earlier) | (Yes) | 5.5 | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Supporto base | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |