当前位置: 首页 > 文档资料 > ES6 入门教程 >

Set.prototype.delete(value)

优质
小牛编辑
124浏览
2023-12-01

此函数从Set中删除指定的值。

语法 (Syntax)

myMap.delete(key);

参数 (Parameters)

  • Key - 要从Map中删除的元素的键

返回值 (Return Value)

如果元素已退出并被删除,则返回true ; 否则它返回false

例子 (Example)

var set = new Set(); 
set.add(10); 
set.add(20); 
set.add(30);
console.log(`Size of Set before delete() :${set.size}`); 
console.log(`Set has 10 before delete() :${set.has(10)}`); 
set.delete(10) 
console.log(`Size of Set after delete() :${set.size}`); 
console.log(`Set has 10 after delete() :${set.has(10)}`) 

输出 (Output)

Size of Set before delete() :3 
Set has 10 before delete() :true 
Size of Set after delete() :2 
Set has 10 after delete() :false