# Delete an element from a Map in JavaScript

By Atta Ur Rehman Shah (https://attacomsian.com/about). Published Dec 11, 2022, updated Jun 7, 2023. Topics: JavaScript.
Canonical URL: https://attacomsian.com/blog/javascript-map-delete-element

> Learn how to use the delete() method to remove an element from a Map in JavaScript.

The `delete()` method can be utilized to remove an element from a `Map` object. This method takes the key name of the element as a parameter. It returns `true` if the element was present in the `Map` object and successfully removed, or `false` if the element does not exist.

```javascript
const map = new Map([
  ['name', 'Alex Hales'],
  ['age', 27],
  ['country', 'United States']
])

console.log(map)
// Map(3) {
//   'name' => 'Alex Hales',
//   'age' => 27,
//   'country' => 'United States'
// }

console.log(map.delete('name')) // true
console.log(map.delete('name')) // false (already removed)
console.log(map.delete('job')) // false (not found)
```

To delete all elements in a `Map` object, the `clear()` method can be used:

```javascript
const map = new Map([
  ['name', 'Alex Hales'],
  ['age', 27],
  ['country', 'United States']
])

map.clear()

console.log(map.size) // 0
console.log(map) // Map(0) {}
```

To gain a deeper understanding of the `Map` object and how to create collections of key-value pairs in JavaScript, refer to [this article](https://attacomsian.com/blog/maps-javascript).
