ES6-地图方法 entries()



此函数返回一个迭代器,其中包含 Map 中每个元素的键值对。

语法

entries() 的语法如下所示 −

map_name.entries()

示例

<script>
   let andy = {ename:"Andrel"},
      varun = {ename:"Varun"},
      prijin = {ename:"Prijin"}

   let empJobs = new Map([
   [andy,'Software Architect'],
   [varun,'Developer']]
   );

   for(let row of empJobs.entries()){
      console.log("key is ",row[0])
      console.log("value is ",row[1])
   }
</script>

以上代码的输出如下所示 −

key is {ename: "Andrel"}
value is Software Architect
key is {ename: "Varun"}
value is Developer
广告