ES6 - Map 方法 values()



此函数返回一个遍历器,该遍历器包含 map 对象中每个元素的值。

语法

values() 语法如下所示 −

map_name.values()

示例

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

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

   for(let role of empJobs.values()){
      console.log(role)
   }
</script>

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

Software Architect
Developer
广告