let arr = [1, 2, 3, 4, 3, 3, 3]
console.log([...new Set(arr)])
// (4) [1, 2, 3, 4]
let arr = [1, 2, 3, 4, 3, 3, 3, 'foo', true]
console.log([...new Set(arr)])
//(6) [1, 2, 3, 4, 'foo', true]
let arr =["a","b","c"];
// ES6 way
const duplicate = [...arr];
// older method
const duplicate = Array.from(arr);
let chars = ['A', 'B', 'A', 'C', 'B'];
let uniqueChars = [];
chars.forEach((c) => {
if (!uniqueChars.includes(c)) {
uniqueChars.push(c);
}
});
console.log(uniqueChars);
Code language: JavaScript (javascript)
let arr = [1, 7, 8, 9, 10, 20, 33, 0, 20, 7, 1]
console.log([... new Set(arr)]
// Output : [1, 7, 8, 9, 10, 20, 33, 0]