Map.prototype.delete
Removes the entry for a key.
Available since: ES2015
Syntax
map.delete(key)Parameters
| Parameter | Type | Description |
|---|---|---|
| key | any | The key. |
Return value
booleantrue if the key existed and was removed.
Examples
Removing an entry:
const cart = new Map([['tea', 2], ['cake', 1]]);
console.log(cart.delete('tea'));
console.log(cart.delete('tea'));
console.log(cart.size);Output:
true
false
1Notes
To remove all entries at once use clear().
See also
- Map.prototype.set — Adds or replaces the value for a key.
- Map.prototype.clear — Removes all entries from a Map.
- delete — Removes a property from an object.
In the tutorial
- Map and Set — The Map and Set collections in JavaScript: a dictionary with keys of any type and a set of unique values.