Encodera

Thanks for reading!

Donate to the site — we work hard for you.

JavaScript reference

Set.prototype.size

The number of values in a Set.

Available since: ES2015

Syntax

set.size

Return value

numberThe number of values.

Examples

How many unique words a text has:

const words = 'the cat and the dog and the bird'.split(' ');
 
console.log(new Set(words).size);

Output:

5

Notes

As with a Map, it is the size property, not length.

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.