DEV Community

Discussion on: 3 ways to remove duplicates in an Array in Javascript

Collapse
 
jasimalrawie profile image
JasimAlrawie

Or
let chars = ['A', 'B', 'A', 'C', 'B'];

let uniqueChars = [];
chars.forEach((e) => {
if (!(e in chars)) {
uniqueChars.push(e);
}
});

console.log(uniqueChars);

Collapse
 
rowild profile image
Robert Wildling

Shouldn't that be if (!(e in uniqueChars)) { ?