reverse() 方法将数组中元素的位置颠倒。

第一个数组元素成为最后一个数组元素,最后一个数组元素成为第一个。

语法

 arr.reverse()

参数

描述

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

示例

例子:颠倒数组中的元素

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

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

console.log(myArray) // ['three', 'two', 'one']

规范

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 AndroidiOS SafariSamsung InternetNode.js
Basic supportChrome Full support 1Edge Full support YesFirefox 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

相关链接

文档标签和贡献者

最后编辑者: fscholz,