array.reverse

array.reverse

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

var a = ['one', 'two', 'three']; a.reverse( console.log(a // ['three', 'two', 'one']

语法

a.reverse()

Return value

颠倒的数组。

描述

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

示例

颠倒数组中的元素

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

var a = ['one', 'two', 'three']; var reversed = a.reverse( console.log(a // ['three', 'two', 'one'] console.log(reversed // ['three', 'two', 'one']

规范

SpecificationStatusComment
ECMAScript 1st Edition (ECMA-262)StandardInitial 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.Living Standard

浏览器兼容性

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic Support1(Yes)15.5(Yes)(Yes)

FeatureAndroidChrome for AndroidEdge mobileFirefox for AndroidIE mobileOpera AndroidiOS Safari
Basic Support(Yes)(Yes)(Yes)1(Yes)(Yes)(Yes)