This translation is in progress.

reverse() metodu dizi elemanlarını tersten sıralar . Dizinin ilk elemanı son eleman olur, son elemanı ilk eleman olur.

Syntax

a.reverse()

Dönen Değer

The reversed array.

Açıklama

reverse metodu dizinin olduğu halini kalıcı olarak değistirir ve değiştirilmiş diziyi döndürür.

reverse is intentionally generic; this method can be called or applied to objects resembling arrays. Objects which do not contain a length property reflecting the last in a series of consecutive, zero-based numerical properties may not behave in any meaningful manner.

Examples

Reversing the elements in an array

The following example creates an array a, containing three elements, then reverses the array. The call to reverse() returns a reference to the reversed array a.

const a = [1, 2, 3];

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

a.reverse(); 

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

Reversing the elements in an array-like object

The following example creates an array-like object a, containing three elements and a length property, then reverses the array-like object. The call to reverse() returns a reference to the reversed array-like object a.

const a = {0: 1, 1: 2, 2: 3, length: 3};

console.log(a); // {0: 1, 1: 2, 2: 3, length: 3}

Array.prototype.reverse.call(a); //same syntax for using apply()

console.log(a); // {0: 3, 1: 2, 2: 1, length: 3}

Specifications

Specification Status Comment
ECMAScript 1st Edition (ECMA-262) Standard Initial definition. Implemented 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

Browser compatibility

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox 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 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

See also

Document Tags and Contributors

Contributors to this page: CankatSoysal
Last updated by: CankatSoysal,