1const names = ['John', 'Paul', 'George', 'Ringo', 'John'];
2
3let unique = [...new Set(names)];
4console.log(unique); // 'John', 'Paul', 'George', 'Ringo'
1const names = ['John', 'Paul', 'George', 'Ringo', 'John'];
2
3function removeDups(names) {
4 let unique = {};
5 names.forEach(function(i) {
6 if(!unique[i]) {
7 unique[i] = true;
8 }
9 });
10 return Object.keys(unique);
11}
12
13removeDups(names); // // 'John', 'Paul', 'George', 'Ringo'
1let a = [10,20,30,10,30];
2let b = a.filter((item,index) => a.indexOf(item) === index);
3console.log(b);
1// Using the Set constructor and the spread syntax:
2
3arrayWithOnlyUniques = [...new Set(arrayWithDuplicates)]
1let a = [10,20,30,50,30];
2let b = a.reduce((unique,item) => unique.includes(item) ? unique: [... unique, item] ,[]);
3console.log(b);