ES6 - Map 方法 get()



如果键匹配,此函数返回该值;如果键未找到,则返回undefined

语法

下面提到了get()的语法,其中,key是要从 Map 对象中返回的元素的键。

map_name.get(key)

示例

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

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

   let value = empJobs.get(varun)
   console.log(value)

   console.log(empJobs.size)
</script>

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

Developer
2
广告