delete() 方法用于移除 Map 对象中指定的元素。

语法

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  

浏览器兼容性

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidEdge MobileFirefox for AndroidOpera for AndroidiOS SafariSamsung InternetNode.js
Basic supportChrome Full support 38Edge Full support 12Firefox Full support 13IE Full support 11Opera Full support 25Safari Full support 8WebView Android Full support 38Chrome Android Full support 38Edge Mobile Full support 12Firefox Android Full support 14Opera Android Full support 25Safari iOS Full support 8Samsung Internet Android Full support Yesnodejs Full support 0.12
Full support 0.12
Full support 0.10
Disabled
Disabled From version 0.10: this feature is behind the --harmony runtime flag.

Legend

Full support  
Full support
User must explicitly enable this feature.
User must explicitly enable this feature.

相关链接

文档标签和贡献者

此页面的贡献者: zhangchen, royl8, Hushabyme, webery
最后编辑者: zhangchen,