Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Array.prototype.reverse()

總結

reverse() 將陣列反轉。陣列中第一個元素變成最後一個, 最後一個變成第一個。

語法

arr.reverse()

參數

無。

敘述

reverse 方法將變換呼叫此方法的陣列的元素至其顛倒的位置, 改變陣列後, 並回傳此陣列之位址。

範例

範例: 反轉陣列中之元素

下列範例創造一個陣列 myArray, 包含三個元素, 然後反轉此陣列。

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

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

規格

規格 狀態 註解
ECMAScript 1st Edition Standard Initial definition. Implemented in JavaScript 1.1.
ECMAScript 5.1 (ECMA-262)
The definition of 'Array.prototype.reverse' in that specification.
Standard  
ECMAScript 6 (ECMA-262)
The definition of 'Array.prototype.reverse' in that specification.
Draft  

瀏覽器相容性

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support 1.0 1.0 (1.7 or earlier) 5.5 (Yes) (Yes)
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support (Yes) (Yes) (Yes) (Yes) (Yes) (Yes)

See also

文件標籤與貢獻者

 此頁面的貢獻者: CYBAI
 最近更新: CYBAI,