This translation is in progress.

Metoda reverse() inversează un array în ceea ce privește poziția elementelor. Primul element din array devine ultimul, iar ultimul element din array devine primul.

var a = ['A', 'B', 'C'];
a.reverse(); 

console.log(a); // ['C', 'B', 'A']

Sintaxa

a.reverse()

Valoarea returnata

Array-ul inversat.

Descriere

Metoda reverse transpune elementele array-ului in ceea ce priveste pozitia, modificand array-ul,  returnand o referinta la acel array.

Example

Inversarea elementelor in array

Urmatorul exemplu creaza un array - a, care contine trei elemente, dupa care inverseaza array-ul. Apelarea metodei reverse() returneaza o referinta la la array-ul inversat a.

var a = ['A', 'B', 'C'];
var reversed = a.reverse(); 

console.log(a);        // ['C', 'B', 'A']
console.log(reversed); // ['C', 'B', 'A']

Specificatii

Specificatii Status Info
ECMAScript 1st Edition (ECMA-262) Standard Initial definit. Implementat 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 Latest Draft (ECMA-262)
The definition of 'Array.prototype.reverse' in that specification.
Draft  

Compatibilitate browser

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
reverseChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 5.5Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support Yesnodejs Full support Yes

Legend

Full support  
Full support

Vezi si

Document Tags and Contributors

Contributors to this page: mdnwebdocs-bot, mvdlele29, andreiTn
Last updated by: mdnwebdocs-bot,