ES6 - Collections Set Method delete()


Advertisements


This function removes the specified value from the Set.

Syntax

myMap.delete(key);

Parameters

  • Key − key of the element to be removed from the Map

Return Value

Returns true if the element exited and was removed; else it returns 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 

es6_collections.htm

Advertisements