reverse() 方法将数组中元素的位置颠倒,并返回该数组。该方法会改变原数组。

语法

 arr.reverse()

参数

描述

reverse 方法颠倒数组中元素的位置,并返回该数组的引用。

示例

例子:颠倒数组中的元素

下例将会创建一个数组 sourceArray,其包含三个元素,然后颠倒该数组。

var sourceArray = ['one', 'two', 'three'];
var reverseArray = sourceArray.reverse();

console.log(sourceArray ) // ['three', 'two', 'one']
console.log(sourceArray === reverseArray); // true

规范

Specification Status Comment
ECMAScript 1st Edition (ECMA-262) Standard Initial definition. Implemented in JavaScript 1.1
ECMAScript 5.1 (ECMA-262)
Array.prototype.reverse
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
Array.prototype.reverse
Standard  

浏览器兼容性

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

相关链接