Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Map.prototype.delete

Removes the entry for a key.

Available since: ES2015

Syntax

map.delete(key)

Parameters

ParameterTypeDescription
keyanyThe key.

Return value

booleantrue if the key existed and was removed.

Examples

Removing an entry:

const cart = new Map([['tea', 2], ['cake', 1]]);
 
console.log(cart.delete('tea'));
console.log(cart.delete('tea'));
console.log(cart.size);

Output:

true
false
1

Notes

To remove all entries at once use clear().

See also

In the tutorial

  • Map and Set — The Map and Set collections in JavaScript: a dictionary with keys of any type and a set of unique values.

Thanks for reading!

Donate to the site — we work hard for you.