ES6 - Map Method delete()



This function is used to remove the specified element from a Map object.

Syntax

The syntax for delete() is given below, where, key is the key of the element to remove from the map.

map_name.delete(key)
where,

Example

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

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

   empJobs.delete(andy) //deleting an element
   console.log(empJobs)
</script>

The output of the above code is as shown below −

{{…} => "Developer"}
Advertisements