ES6 - Map Method keys()



This function returns an iterator that contains the keys for each element in the map object.

Syntax

The syntax for keys() is given below

map_name.keys()

Example

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

The output of the above code is as mentioned below −

Andrel
Varun
Advertisements