delete()
方法用于移除 Map
对象中指定的元素。
The source for this interactive example is stored in a GitHub repository. If you'd like to contribute to the interactive examples project, please clone https://github.com/mdn/interactive-examples and send us a pull request.
语法
myMap.delete(key);
参数
- key
-
必须。从
Map
对象中移除的元素的键。
返回值
- Boolean
-
如果
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 |
---|---|---|
ECMAScript 2015 (6th Edition, ECMA-262) Map.prototype.delete |
Standard | Initial definition. |
ECMAScript Latest Draft (ECMA-262) Map.prototype.delete |
Draft |
浏览器兼容性
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.
Update compatibility data on GitHub
Desktop | Mobile | Server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
delete |
Chrome Full support 38 | Edge Full support 12 | Firefox Full support 13 | IE Full support 11 | Opera Full support 25 | Safari Full support 8 | WebView Android Full support 38 | Chrome Android Full support 38 | Firefox Android Full support 14 | Opera Android Full support 25 | Safari iOS Full support 8 | Samsung Internet Android Full support 3.0 | nodejs Full support 0.12
|
Legend
- Full support
- Full support
- User must explicitly enable this feature.
- User must explicitly enable this feature.