NodeList.entries()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.

La méthode NodeList.entries() renvoie un itérateur permettant de parcourir toutes les paires clé / valeur contenues dans cet objet . Les valeurs sont des objets Node.

Syntaxe

js
list.entries();

Valeur retournée

renvoie un itérateur.

Exemple

js
var node = document.createElement("div");
var kid1 = document.createElement("p");
var kid2 = document.createTextNode("hey");
var kid3 = document.createElement("span");
node.appendChild(kid1);
node.appendChild(kid2);
node.appendChild(kid3);

var list = node.childNodes;

// Utiliser for..of
for (var entry of list.entries()) {
  console.log(entry);
}

résultat :

Array [ 0, <p> ]
Array [ 1, #text "hey" ]
Array [ 2, <span> ]

Spécifications

No specification found

No specification data found for api.NodeList.entries.
Check for problems with this page or contribute a missing spec_url to mdn/browser-compat-data. Also make sure the specification is included in w3c/browser-specs.

Compatibilité des navigateurs

BCD tables only load in the browser

Voir aussi