ES6 - Map Method delete(key)



Removes any value associated to the key and returns the value that Map.prototype.has(key) would have previously returned. Map.prototype.has(key) will return false afterwards.

Syntax

myMap.delete(key);             

Parameters

Key − key of the element to be removed from the Map.

Return Value

Returns true if the element exited and was removed; else it returns false.

Example

var myMap = new Map(); 
myMap.set("id", "admin"); 
myMap.set("pass", "admin@123"); 
console.log(myMap.has("id")); 

myMap.delete("id"); 
console.log(myMap.has("id")); 

Output

true 
false    
Advertisements