Set.prototype.size
The number of values in a Set.
Available since: ES2015
Syntax
set.sizeReturn 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:
5Notes
As with a Map, it is the size property, not length.
See also
- Map.prototype.size — The number of entries in a Map.
- Array.prototype.length — The number of elements in an array.
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.