ES6 - Map 方法 keys()



该函数返回一个 迭代器,它包含 map 对象中每个元素的键

语法

keys() 的语法如下所示

map_name.keys()

示例

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

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

   for(let emp of empJobs.keys()){
      console.log(emp.ename)
   }
</script>

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

Andrel
Varun
广告