Map.prototype.delete()
BaselineWidely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Thedelete()
method ofMap
instances removes the specified element from this map bykey.
Try it
const map1 = new Map();map1.set("bar", "foo");console.log(map1.delete("bar"));// Expected result: true// True indicates successful removalconsole.log(map1.has("bar"));// Expected result: false
Syntax
js
mapInstance.delete(key)
Parameters
key
The key of the element to remove from the
Map
object.
Return value
true
if an element in theMap
object existed and has been removed, orfalse
if the element does not exist.
Examples
Using delete()
js
const myMap = new Map();myMap.set("bar", "foo");console.log(myMap.delete("bar")); // Returns true. Successfully removed.console.log(myMap.has("bar")); // Returns false. The "bar" element is no longer present.
Specifications
Specification |
---|
ECMAScript® 2026 Language Specification # sec-map.prototype.delete |