Example 1 — After clear
size is 0.
JavaScript
const s = new Set([1]);
s.clear();
console.log(s.size);How It Works
- clear removes all values.
set.size is the number of unique values in a Set.
const s = new Set([1, 1, 2]);
console.log(s.size);
s.add(3);
console.log(s.size);size is 0.
const s = new Set([1]);
s.clear();
console.log(s.size);CODETOFUN NEWS
Get the latest IT news, programming updates, and technology trends directly on your phone.
Your daily dose of tech, straight to your feed.
6 people found this page helpful