javascript set contains 1

javascript set contains

// Use to remove duplicate elements from the array 

const numbers = [2,3,4,4,2,3,3,4,4,5,5,6,6,7,5,32,3,4,5]

//spreading numbers of the object into an array using the new operator
console.log([...new Set(numbers)]) 

// [2, 3, 4, 5, 6, 7, 32]

Here is what the above code is Doing:
1. We are creating a new Set object and passing the numbers array to it.
2. The Set object will remove all the duplicate elements from the array.
3. Then we are spreading the Set object into an array using the new operator.

Similar Posts