Set.prototype.clear()
‘clear’
method remove all the elements from set.
function printSetInfo(set){ console.log("***********************************"); console.log("Number Of Elements : " + set.size); for(var key of countries){ console.log(key); } console.log("***********************************"); } var countries = new Set(); countries.add("India"); countries.add("Australia"); countries.add("Canada"); countries.add("Germany"); printSetInfo(countries); console.log("\nClearning all the elements from set\n"); countries.clear(); printSetInfo(countries);
Output
***********************************
Number
Of Elements : 4
India
Australia
Canada
Germany
***********************************
Clearning
all the elements from set
***********************************
Number
Of Elements : 0
***********************************
No comments:
Post a Comment