--- title: Map.prototype.delete() slug: Web/JavaScript/Reference/Global_Objects/Map/delete tags: - ECMAScript 2015 - JavaScript - Map - Method - Prototype translation_of: Web/JavaScript/Reference/Global_Objects/Map/delete ---
delete()
方法用于移除 Map
对象中指定的元素。
myMap.delete(key);
Map
对象中移除的元素的键。Map
对象中存在该元素,则移除它并返回 true
;否则如果该元素不存在则返回 false
。delete
方法var myMap = new Map(); myMap.set("bar", "foo"); myMap.delete("bar"); // 返回 true。成功地移除元素 myMap.has("bar"); // 返回 false。"bar" 元素将不再存在于 Map 实例中
Specification | Status | Comment |
---|---|---|
{{SpecName('ES6', '#sec-map.prototype.delete', 'Map.prototype.delete')}} | {{Spec2('ES6')}} | Initial definition. |
{{SpecName('ESDraft', '#sec-map.prototype.delete', 'Map.prototype.delete')}} | {{Spec2('ESDraft')}} |
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
{{Compat("javascript.builtins.Map.delete")}}