怎样单独遍历NodeList的键值和键值对

Posted aisowe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了怎样单独遍历NodeList的键值和键值对相关的知识,希望对你有一定的参考价值。

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> ]
// ...

 

以上是关于怎样单独遍历NodeList的键值和键值对的主要内容,如果未能解决你的问题,请参考以下文章

排序数组以及遍历普通对象的键值对以及如何遍历一个不同键值的对象数组

map集合中的键值对对象遍历

Go语言 遍历map中的键值对

HashMapHashTableConcurrentHashMap详解

C 语言文件操作 ( 配置文件读写 | 写出或更新配置文件 | 追加键值对数据 | 更新键值对数据 )

javascript键值对中的key可以是变量吗?