DEV Community

Discussion on: Remove duplicates from an Array the short & sweet way!

Collapse
 
ajmalhassan profile image
Ajmal Hassan

No, it won't.

The above method only works for Primitive Types (number, string, boolean, null, undefined) in the array.

so,

const primitivesArr = [true, false, true, false, undefined, 1, undefined, 'hello', 1, 'hello']

console.log([...new Set(primitivesArr)])
// output: [true, false, undefined, 1, "hello"]

For objects, you'll have to use filter()

Collapse
 
ankit199 profile image
Ankit kumar shukla

okk ..thank you