Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Set.prototype.clear

Removes all values from a Set.

Available since: ES2015

Syntax

set.clear()

Return value

undefinedReturns nothing.

Examples

Clearing a set:

const selected = new Set([1, 2, 3]);
selected.clear();
 
console.log(selected.size);

Output:

0

Notes

If you need a new empty Set and the old one must stay as is, just create new Set().

See also

In the tutorial

  • Map and Set — The Map and Set collections in JavaScript: a dictionary with keys of any type and a set of unique values.

Thanks for reading!

Donate to the site — we work hard for you.