JS Built-ins
Setbeginner

Set Constructor β€” from string

πŸ“– Usage Example
const s1 = new Set()          // empty
const s2 = new Set([1, 2, 3]) // from array
console.log(s2.size) // β†’ 3

Use the Set constructor to create a new set, optionally passing an iterable.

Set Constructor

new Set('hello') creates a Set of unique characters. 'hello' has 4 unique chars: h,e,l,o.

Challenge: Verify that new Set('hello').size equals 4.

πŸ’‘ Hints (1)
  • β€’ Strings are iterables β€” 'hello' has chars h,e,l,l,o but 'l' is deduped, giving 4 unique chars