DEV Community

Discussion on: JavaScript: How to Remove Duplicate Values from Arrays

Collapse
 
4umfreak profile image
Mark Voorberg • Edited

Same using .reduce()...

let myArray = [1,2,2,"hello world",4,5,5, {moo: "cow"}];
let myObject = myArray.reduce((acc, x) => {acc[x]=0; return acc}, {});
let noDuplicates = Object.keys(myObject);