Map

Map.prototype.delete

Removes the specified element from a Map object by key

Syntax

JavaScript
map.delete(key)

Parameters

ParameterTypeDescription
keyKThe key of the element to remove

Return Value

true if an element existed and has been removed, false otherwise

Examples

Basic Usage
const map = new Map([['a', 1], ['b', 2]]);
console.log(map.delete('a')); // true
console.log(map.delete('c')); // false
console.log(map.size); // 1
Practical Example
const sessions = new Map<string, { user: string }>();
sessions.set('abc123', { user: 'Alice' });
function logout(token: string) {
  return sessions.delete(token);
}
Advanced Usage
const map = new Map([['x', 1], ['y', 2], ['z', 3]]);
for (const [key, val] of map) {
  if (val < 2) map.delete(key);
}
console.log([...map.keys()]); // ['y', 'z']

Understanding Map.prototype.delete

The Map.prototype.delete method in JavaScript removes the specified element from a Map object by key. It belongs to the Map object and is one of the most widely used methods for working with map values in modern JavaScript and TypeScript applications.

The method signature is map.delete(key). It accepts 1 parameter: key. When called, it returns true if an element existed and has been removed, false otherwise. Understanding when and how to use delete() helps you write more expressive, readable code.

Common use cases for Map.prototype.delete include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like map-clear, map-has, map-set, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Map.prototype.delete is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.

Browser Compatibility

Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.

Related Methods

More Map Methods

Other methods in the Map object

Related Tools

More Map Methods

Explore JavaScript Methods

Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.