Map.prototype.delete()

Removes a key and its value from a Map.

Since ES2015 (ES6) Spec ↗

Syntax

map.delete(key)

Returns

boolean — `true` if the key existed and was removed, otherwise `false`.

Examples

const m = new Map([["a", 1], ["b", 2]]);
console.log(m.delete("a"));
console.log(m.has("a"));
Output
true
false
const m = new Map();
console.log(m.delete("nope"));
Output
false

Notes

- Returns a boolean indicating whether anything was removed. - To remove all entries use `map.clear()`.

Browser & runtime support

EnvironmentSince version
chrome 38
firefox 13
safari 8
edge 12
node 0.12

See also