JavaScript Map delete() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Map

Definition

map.delete(key) removes the entry for key and returns true. If the key was not stored, it does nothing and returns false. It never throws. After a successful delete, map.size goes down by one. Other entries stay in place.

Remember
map.delete(key)  → true or false

key was stored      → entry removed, true
key not stored      → nothing happens, false
second delete       → false
map.size            → drops by 1 when true

only one key is removed; the rest stay

Syntax

Call delete on a Map with the key you want to forget.

JavaScript
map.delete(key)
CallWhat it does
map.delete(key)Remove the entry for key. Gives true if one was removed.
const removed = map.delete(key)Keep the result when you need to know whether something was actually there.

Built into JavaScript since ES2015. To remove every entry at once, see clear().

Library declarations
JavaScript
map.delete(key)   // returns a boolean

// key: any value; SameValueZero matching
// never throws

Parameters

ParameterDescription
keyRequired. The key whose entry should be removed. Any value works; a missing key simply gives false.

Return Value

Return ValueDescription
trueAn entry for the key existed and has been removed.
falseThere was no entry for the key.

JavaScript Examples

Example 1 — Remove One Entry

Delete a score by name, then check that it is gone while another score stays.

JavaScript
const scores = new Map();
scores.set("Ann", 10);
scores.set("Bob", 8);

console.log(scores.delete("Ann"));   // true
console.log(String(scores.get("Ann"))); // undefined
console.log(scores.get("Bob"));      // 8
Try It Yourself

How It Works

  1. The first delete finds the entry. scores.delete("Ann") removes Ann and reports it with true.
  2. The entry is really gone. Right after the removal, get("Ann") answers undefined.
  3. Other keys stay. Bob was never deleted, so get("Bob") still returns 8.

Example 2 — Deleting a Missing Key

Try to remove a key that was never stored. Nothing changes, and the result is false.

JavaScript
const tags = new Map();
tags.set("js", true);

console.log(tags.delete("css"));   // false
console.log(tags.has("js"));       // true
console.log(tags.size);            // 1
Try It Yourself

How It Works

  1. A missing key returns false. delete("css") finds nothing, changes nothing, and answers false.
  2. Existing keys are untouched. has("js") is still true.
  3. Size stays the same. Because nothing was removed, size remains 1.

Example 3 — Delete and Watch size

Start with three product ids. Delete one, then try to delete it again, and read size each time.

JavaScript
const stock = new Map([
  ["mug", 12],
  ["cup", 4],
  ["bowl", 7]
]);

console.log(stock.size);              // 3
console.log(stock.delete("cup"));     // true
console.log(stock.size);              // 2
console.log(stock.delete("cup"));     // false
console.log(stock.size);              // 2
Try It Yourself

How It Works

  1. Start with three pairs. The constructor fills the Map from an array of pairs, so size begins at 3.
  2. A successful delete shrinks size. delete("cup") returns true and size drops to 2.
  3. A second delete does nothing. The same call again returns false, and size stays 2.

Browser & Runtime Support

Map.prototype.delete() is part of ES2015 (ES6), together with WeakMap, Set, and WeakSet.

✓ Baseline · ES2015

Map.prototype.delete()

Works in every modern browser, plus Node.js, Deno, and Bun. Internet Explorer 11 has a basic Map with set(), get(), has(), delete(), clear(), and size.

98% Modern browser support
Google Chrome 36+ · Desktop & Mobile
Full support
Mozilla Firefox 6+ · Desktop & Mobile
Full support
Apple Safari 8+ · macOS & iOS
Full support
Microsoft Edge 12+
Full support
Node.js 0.12+ · every current release
Supported
Deno All releases
Supported
Internet Explorer IE 11 · no constructor argument
Basic
Map.prototype.delete() Excellent

Bottom line: Safe to use in any modern browser and runtime. delete is a reserved word, but it is fine as a method name, so map.delete(key) works everywhere Map does.

Frequently Asked Questions

It removes the entry for a key from the Map. It returns true if an entry was removed and false if there was nothing to remove.
No. A missing key simply returns false. Nothing else in the Map changes.
When delete() returns true, size goes down by one. When it returns false, size stays the same.
Call clear(). That empties the same Map object in one step. Or replace the variable with new Map() if you want a brand-new object.
No. It only removes the Map entry. The key value itself, and any other references to it, are untouched.

Next: clear()

Empty the whole Map in one call, and see how clear() differs from a new Map().

clear() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful