• Skip to main content
  • Skip to search
  • Skip to select language
    • Technologies Overview
    • HTML
    • CSS
    • JavaScript
    • Graphics
    • HTTP
    • APIs
    • Browser Extensions
    • MathML
    • Learn web development
    • Tutorials
    • References
    • Developer Guides
    • Accessibility
    • Game development
    • ...more docs
    • Send Feedback
    • Contribute to MDN
    • Report a content issue 🌐
    • Report a platform issue 🌐
  1. Web technology for developers
  2. JavaScript
  3. JavaScript reference
  4. Standard built-in objects
  5. Map
  6. Map.prototype.clear()
  • Change language

Table of contents

  • Syntax
  • Examples
  • Specifications
  • Browser compatibility
  • See also

Map.prototype.clear()

The clear() method removes all elements from a Map object.

Syntax

clear()

Return value

undefined.

Examples

Using clear()

var myMap = new Map();
myMap.set('bar', 'baz');
myMap.set(1, 'foo');

myMap.size;       // 2
myMap.has('bar'); // true

myMap.clear();

myMap.size;       // 0
myMap.has('bar')  // false

Specifications

Specification
ECMAScript Language Specification
# sec-map.prototype.clear

Browser compatibility

BCD tables only load in the browser

See also

  • Map

Found a problem with this page?

  • Edit on GitHub
  • Source on GitHub
  • Report a problem with this content on GitHub
  • Want to fix the problem yourself? See our Contribution guide.

Last modified: Jun 22, 2021, by MDN contributors

Change your language

Related Topics

  1. Standard built-in objects
  2. Map
  3. Properties
    1. get Map[@@species]
    2. Map.prototype[@@toStringTag]
    3. Map.prototype.size
  4. Methods
    1. Map.prototype[@@iterator]()
    2. Map.prototype.clear()
    3. Map.prototype.delete()
    4. Map.prototype.entries()
    5. Map.prototype.forEach()
    6. Map.prototype.get()
    7. Map.prototype.has()
    8. Map.prototype.keys()
    9. Map.prototype.set()
    10. Map.prototype.values()
  5. Inheritance:
  6. Function
  7. Properties
    1. Function.arguments
    2. Function.caller
    3. Function.displayName
    4. Function.length
    5. Function.name
  8. Methods
    1. Function.prototype.apply()
    2. Function.prototype.bind()
    3. Function.prototype.call()
    4. Function.prototype.toSource()
    5. Function.prototype.toString()
  9. Object
  10. Properties
    1. Object.prototype.constructor
    2. Object.prototype.__proto__
  11. Methods
    1. Object.prototype.__defineGetter__()
    2. Object.prototype.__defineSetter__()
    3. Object.prototype.__lookupGetter__()
    4. Object.prototype.__lookupSetter__()
    5. Object.prototype.hasOwnProperty()
    6. Object.prototype.isPrototypeOf()
    7. Object.prototype.propertyIsEnumerable()
    8. Object.setPrototypeOf()
    9. Object.prototype.toLocaleString()
    10. Object.prototype.toSource()
    11. Object.prototype.toString()
    12. Object.prototype.valueOf()
  • Web Technologies
  • Learn Web Development
  • About MDN
  • Feedback
  • About
  • MDN Web Docs Store
  • Contact Us
  • Firefox

MDN

  • MDN on Twitter
  • MDN on Github

Mozilla

  • Mozilla on Twitter
  • Mozilla on Instagram

© 2005-2022 Mozilla and individual contributors. Content is available under these licenses.

  • Terms
  • Privacy
  • Cookies