DEV Community

Discussion on: Code Snippet Series: Get Unique Values from Array

Collapse
 
functional_js profile image
Functional Javascript

Correct, these funcs work with the primitives (string and number).

Ref types (comparing objects and arrays) require custom logic, even if working with Set and Map.

eg...

const aDups = [{ id: 1 }, { id: 1 }, { id: 1 }, { id: 1}];
const setDups = new Set(aDups)
console.log(setDups)

// output:
// Set(4) { { id: 1 }, { id: 1 }, { id: 1 }, { id: 1 } }