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']
规范
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. | Living Standard | |
浏览器兼容性
Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic Support | 1 | (Yes) | 1 | 5.5 | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic Support | (Yes) | (Yes) | (Yes) | 1 | (Yes) | (Yes) | (Yes) |