The size property of the Set object in JavaScript returns the number of values in the Set object.
The syntax of Set.size property is:
Set.prototype.size
This size property of Set returns the number of values in the Set object.
Set.size returns value of type number
.
In JavaScript, we can use the size
property to get the number of values in a Set object.
For example,
set
with initial values.size
property to get the number of values in the set
.console.log()
.const set = new Set(['a', 'b', 'c']);
const size = set.size;
console.log(size);
3
In JavaScript, we can use the size
property to get the number of values in a Set object after adding values.
For example,
set
with initial values.add()
method to add new values to the set
.size
property to get the updated number of values in the set
.console.log()
.const set = new Set(['a', 'b']);
set.add('c');
const size = set.size;
console.log(size);
3
In JavaScript, we can use the size
property to get the number of values in a Set object after deleting values.
For example,
set
with initial values.delete()
method to remove values from the set
.size
property to get the updated number of values in the set
.console.log()
.const set = new Set(['a', 'b', 'c']);
set.delete('b');
const size = set.size;
console.log(size);
2
In this JavaScript tutorial, we learned about size property of Set: the syntax and few working examples with output and detailed explanation for each example.