Array.prototype.reverse()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Resumo
O método reverse()
inverte os itens de um array. O primeiro elemento do array se torna o último e o último torna-se o primeiro.
Sintaxe
arr.reverse()
Parâmetros
Nenhum.
Descrição
O método reverse
transpõe os elementos do objeto array no mesmo lugar, mutando o array, e retornando uma referência para o mesmo.
Exemplos
Exemplo: Invertendo os elementos em um array
O seguinte exemplo cria um array myArray
, contendo três elementos, em seguida inverte-o.
js
var myArray = ["one", "two", "three"];
myArray.reverse();
console.log(myArray); // ['three', 'two', 'one']
Especificações
Specification |
---|
ECMAScript® 2025 Language Specification # sec-array.prototype.reverse |
Compatibilidade com navegador
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
reverse |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.