--- title: Map.prototype.clear() slug: Web/JavaScript/Reference/Global_Objects/Map/clear tags: - ECMAScript 2015 - JavaScript - Map translation_of: Web/JavaScript/Reference/Global_Objects/Map/clear ---
clear()
方法会移除Map对象中的所有元素。
myMap.clear();
{{jsxref("undefined")}}.
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
Specification | Status | Comment |
---|---|---|
{{SpecName('ES2015', '#sec-map.prototype.clear', 'Map.prototype.clear')}} | {{Spec2('ES2015')}} | Initial definition. |
{{SpecName('ESDraft', '#sec-map.prototype.clear', 'Map.prototype.clear')}} | {{Spec2('ESDraft')}} |
{{Compat("javascript.builtins.Map.clear")}}