entries() 方法會回傳一個包含陣列中每一個索引之鍵值對(key/value pairs)的新陣列迭代器(Array Iterator)物件。

語法

a.entries()

回傳值

一個新的 Array 迭代器物件。

範例

使用 for…of 進行迭代

var a = ['a', 'b', 'c'];
var iterator = a.entries();

for (let e of iterator) {
  console.log(e);
}
// [0, 'a']
// [1, 'b']
// [2, 'c'] 

規範

規格 狀態 備註
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Array.prototype.entries' in that specification.
Standard 首次定義。
ECMAScript Latest Draft (ECMA-262)
The definition of 'Array.prototype.entries' in that specification.
Draft  

瀏覽器相容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung InternetNode.js
Basic supportChrome Full support 38Edge Full support YesFirefox Full support 28IE No support NoOpera Full support 25Safari Full support 8WebView Android Full support YesChrome Android Full support YesEdge Mobile Full support YesFirefox Android Full support 28Opera Android Full support YesSafari iOS Full support 8Samsung Internet Android Full support Yesnodejs Full support 0.12

Legend

Full support  
Full support
No support  
No support

參見

文件標籤與貢獻者

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