ES6 - Map Method has()


Advertisements

This function returns true if an element with the specified key exists; otherwise it returns false.

Syntax

The syntax for has() is given below, where, key is the key of the element to test for presence.

myMap.has(key)

Example

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

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

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

The output of the above code is as mentioned below −

false
2
Advertisements