entries()方法回傳一個包含陣列所有索引之
鍵值組的新陣列迭代器(Array Iterator)
物件。
語法
arr.entries()
範例
var arr = ['a', 'b', 'c']; var eArr = arr.entries(); console.log(eArr.next().value); // [0, 'a'] console.log(eArr.next().value); // [1, 'b'] console.log(eArr.next().value); // [2, 'c']
同上,使用 for…of 迴圈:
var arr = ['a', 'b', 'c']; var eArr = arr.entries(); for (let e of eArr) { console.log(e); }
規格
瀏覽器相容性
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | 38 | 28 (28) | No support | 25 | 7.1 |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | No support | No support | 28.0 (28) | No support | No support | 8.0 |