JS Built-ins
← Map26 / 55
Mapdeletebeginner

Map delete() β€” returns true for existing

πŸ“– Usage Example
const m = new Map([['a', 1], ['b', 2]])
m.delete('a')   // β†’ true
m.delete('z')   // β†’ false
console.log(m.size) // β†’ 1

Use Map.delete() to remove a key; it returns true if the key existed.

Map.prototype.delete()

delete(key) removes the key and returns true if the key existed.

Challenge: Verify that delete() returns true for an existing key.

πŸ’‘ Hints (1)
  • β€’ delete() returns true when the key existed and was removed