What is the Set object used for in JavaScript?
a) To store unique values of any type
b) To create a collection of key-value pairs
c) To perform mathematical operations on arrays
d) To sort the elements in an array
Answer:
a) To store unique values of any type
Explanation:
The Set
object in JavaScript allows you to store unique values of any type, whether primitive values or object references. A value in a Set
may only occur once, making it useful for filtering duplicates.