CKTIS / JavaScript
Set.prototype.size — number of elements in a set
The size property reports the current number of distinct values in a Set. Read it as set.size, without parentheses. An empty set has size 0, and adding the same value again does not increase its size.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
set.sizeSet.prototype.size is an accessor property: the getter inherited by Set instances returns the current number of stored elements as a Number. Use set.size, not set.size() or set.length. An empty set returns 0.
A set stores each distinct value only once. Adding an existing value does not increase size; deleting a present value decreases it, and clear() removes all elements. Each read reflects the set's current state. A number previously saved in a variable does not update automatically.
The built-in property has no setter. Assigning to set.size does not change the element count: in strict mode it throws TypeError, and outside strict mode it is ignored, provided the property has not been shadowed. Change the set's contents rather than assigning its size.
The getter requires a receiver with the internal slot [[SetData]]; it does not work on a plain object pretending to be a set. Reading Set.prototype.size directly also throws TypeError because the prototype itself lacks that slot. This is part of the ECMAScript standard library, not a separate Web API; the language specification is not a browser compatibility table.
Examples
const values = new Set(["a", "b", "a"]);
console.log(values.size);
values.add("b");
console.log(values.size);
values.delete("a");
console.log(values.size);
values.clear();
console.log(values.size);Result
2 2 1 0
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.