NodeList: keys() メソッド
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2017年10月.
NodeList.keys() メソッドは、このオブジェクトに含まれるすべてのキーを走査することができるイテレーターを返します。キーは unsigned integer です。
構文
js
keys()
返値
イテレーターを返します。
例
js
const node = document.createElement("div");
const kid1 = document.createElement("p");
const kid2 = document.createTextNode("hey");
const kid3 = document.createElement("span");
node.appendChild(kid1);
node.appendChild(kid2);
node.appendChild(kid3);
let list = node.childNodes;
// for...of の使用
for (const key of list.keys()) {
console.log(key);
}
結果は次の通りです。
0 1 2
ブラウザーの互換性
Loading…