NodeList.keys()

NodeList.keys() 方法返回 iterator ,此方法允许遍历这个对象中包含的所有的键,即使这个键是 unsigned integer(无符号整数).

语法

nodeList.keys();

返回值

返回 iterator.

例子

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; 

// Using for..of 
for(var key of list.keys()) { 
   console.log(key); 
}

结果是:

0
1
2

浏览器兼容

此页面的兼容性表格是根据结构化数据生成的,如果您想为数据做出贡献,请查看 https://github.com/mdn/browser-compat-data 并向我们发起请求。

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
keysChrome Full support 51Edge Full support 16Firefox Full support 50IE No support NoOpera Full support 38Safari Full support 10WebView Android Full support 51Chrome Android Full support 51Firefox Android Full support 50Opera Android ? Safari iOS Full support 10Samsung Internet Android Full support 5.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown

相关链接