1. 单独遍历键: NodeList.prototype.keys();

2. 单独遍历值: NodeList.prototype.values();

3. 遍历键值对: NodeList.prototype.entries();

 

var children = document.body.childNodes;

for (var key of children.keys()) {
  console.log(key);
}
// 0
// 1
// 2
// ...

for (var value of children.values()) {
  console.log(value);
}
// #text
// <script>
// ...

for (var entry of children.entries()) {
  console.log(entry);
}
// Array [ 0, #text ]
// Array [ 1, <script> ]
// ...

 

相关文章:

  • 2021-12-05
  • 2022-12-23
  • 2022-12-23
  • 2021-09-28
  • 2023-03-19
  • 2022-12-23
  • 2021-06-26
  • 2021-05-15
猜你喜欢
  • 2021-07-11
  • 2021-12-14
  • 2021-07-27
  • 2021-09-02
  • 2021-10-16
  • 2021-11-11
  • 2022-12-23
相关资源
相似解决方案