Die entries() Methode gibt ein neues Array Iterator Objekt zurück, dass Schlüssel/Wert Paare für jeden Index im Array enthält.
Syntax
arr.entries()
Rückgabewert
Ein neues Array-iterator Objekt.
Beispiele
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']
Das gleiche wie oben, nur mit einer for...of Schleife:
var arr = ['a', 'b', 'c'];
var eArr = arr.entries();
for (let e of eArr) {
console.log(e);
}
Spezifikationen
| Spezifikation | Status | Kommentar |
|---|---|---|
| ECMAScript 2015 (6th Edition, ECMA-262) Die Definition von 'Array.prototype.entries' in dieser Spezifikation. |
Standard | Initiale Definition. |
| ECMAScript 2017 Draft (ECMA-262) Die Definition von 'Array.prototype.entries' in dieser Spezifikation. |
Entwurf |
Browserkompatibilität
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | 38 | 28 (28) | Nicht unterstützt | 25 | 7.1 |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | Nicht unterstützt | Nicht unterstützt | 28.0 (28) | Nicht unterstützt | Nicht unterstützt | 8.0 |