Map.prototype.delete()
map.delete(key) Returns:
boolean · Updated March 13, 2026 · Map and Set map delete remove
The delete() method removes a single entry from a Map by key. It returns true when the key existed and the entry was removed, or false when the key was not present. That boolean return value makes Map.prototype.delete() handy for cache invalidation, conditional cleanup, and other code paths where you want to know whether anything actually changed.
Syntax
map.delete(key)
Parameters
| Parameter | Type | Description |
|---|---|---|
| key | any | The key to remove from the map |
Return Value
Returns true if the key existed and was removed. Returns false if the key was not found.
Examples
Basic usage
const roles = new Map([
['alice', 'admin'],
['bob', 'editor'],
['charlie', 'viewer']
]);
console.log(roles.delete('bob'));
// true
console.log(roles.has('bob'));
// false
console.log(roles.size);
// 2
Deleting a missing key
const cache = new Map([['theme', 'dark']]);
console.log(cache.delete('language'));
// false
console.log(cache.size);
// 1
Conditional invalidation
const sessions = new Map([
['a1', { user: 'alice' }],
['b2', { user: 'bob' }]
]);
function invalidateSession(id) {
if (sessions.delete(id)) {
return `Session ${id} removed`;
}
return `Session ${id} was not active`;
}
console.log(invalidateSession('a1'));
// Session a1 removed
See Also
- Map.prototype.get() — read a value by key
- Map.prototype.has() — check whether a key exists
- Map.prototype.clear() — remove every entry from a map