To get the size of a set in TypeScript, you can use the size
property of the set.
In this example,
set1
using the Set
constructor with some elements.size
property of the set object set1
to get the number of elements in the set.size
property returns the size of the set.const set1 = new Set(['apple', 'banana', 'cherry']);
console.log('Size of set1:', set1.size);
Size of set1: 3
In this example,
emptySet
using the Set
constructor.size
property of the set object emptySet
to get the number of elements in the set.size
property returns 0.const emptySet = new Set();
console.log('Size of emptySet:', emptySet.size);
Size of emptySet: 0
In this tutorial, we learned How to Get Length of a Set in TypeScript language with well detailed examples.