[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/Array/reverse [Back]  [Original]

Array.prototype.reverse() - JavaScript | MDN

Esta pgina ha sido traducida del ingls por la comunidad. Aprende ms y nete a la comunidad de MDN Web Docs.

View in English Always switch to English

Array.prototype.reverse()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since julio de 2015.

El mtodo reverse() invierte el orden de los elementos de un array in place. El primer elemento pasa a ser el ltimo y el ltimo pasa a ser el primero.

In this article

Prubalo

const array1 = ["one", "two", "three"];
console.log("array1:", array1);
// Expected output: "array1:" Array ["one", "two", "three"]

const reversed = array1.reverse();
console.log("reversed:", reversed);
// Expected output: "reversed:" Array ["three", "two", "one"]

// Careful: reverse is destructive -- it changes the original array.
console.log("array1:", array1);
// Expected output: "array1:" Array ["three", "two", "one"]

Sintaxis

reverse()

Valor devuelto

El array invertido.

Descripcin

El mtodo reverse cruza los elementos del objeto matriz invocados en su lugar, mutando la matriz, y retornando una referencia a la misma.

Ejemplos

Colocar al revs los elementos de un array

El siguiente ejemplo crea un array a que contiene tres elementos y luego lo invierte. La llamada a reverse() devuelve una referencia al array a invertido.

js
const a = [1, 2, 3];

console.log(a); // [1, 2, 3]

a.reverse();

console.log(a); // [3, 2, 1]

Especificaciones

Specification
ECMAScript 2027 LanguageSpecification
# sec-array.prototype.reverse

Compatibilidad con navegadores

Ver tambin


Web Proxy Viewer  |  New URL  |  Original Page