ES6 - Map Method get()


Advertisements

This function returns value if the key is matched or returns undefined if the key is not found.

Syntax

The syntax for get() is mentioned below, where, key is the key of the element to return from the Map object.

map_name.get(key)

Example

<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>

The output of the above code is as mentioned below −

Developer
2
Advertisements