To remove an element from a map use the .delete()
method.
map.delete(key);
Example:
const map = new Map([[1, 2], [3, 4]]);
console.log(map.get(3)); // 4
map.delete(3);
console.log(map.get(3)); // undefined
This method returns true
if the element existed and has been removed, otherwise false
:
const map = new Map([[1, 2], [3, 4]]);
console.log(map.delete(1)); // true
console.log(map.delete(7)); // false