How do you remove duplicates from an array in JavaScript?

How do you remove duplicates from an array in JavaScript?

a) Using Set()
b) Using Array.filter()
c) Using Array.reduce()
d) Using Array.map()

Answer:

a) Using Set()

Explanation:

One of the easiest ways to remove duplicates from an array in JavaScript is by using Set(). A Set object stores unique values, and you can convert the array to a Set and back to an array to remove duplicates.

Reference:

JavaScript MCQ (Multiple-Choice Questions)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top