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
3let unique = [...new Set(names)];
4console.log(unique); // 'John', 'Paul', 'George', 'Ringo'
5
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'
1const arr = [1, 2, [3, 4]];
2
3// To flat single level array
4arr.flat();
5// is equivalent to
6arr.reduce((acc, val) => acc.concat(val), []);
7// [1, 2, 3, 4]
8
9// or with decomposition syntax
10const flattened = arr => [].concat(...arr);
11