mySet.delete(key);


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

语法

mySet.delete(key);

参数

  • 键 - 要从Set中删除的元素的键

返回值

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

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)}`)

输出

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