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 |
Desktop | Mobile | Server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
reverse | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 5.5 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Edge Mobile Full support Yes | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes | nodejs Full support Yes |