1var array = [1, 2, 2, 3, 3, 4, 5, 6, 2, 3, 7, 8, 5, 22, 1, 2, 511, 12, 50, 22];
2
3console.log([...new Set(
4 array.filter((value, index, self) => self.indexOf(value) !== index))]
5);
1var names = ['Mike', 'Matt', 'Nancy', 'Adam', 'Jenny', 'Nancy', 'Carl']
2
3var uniq = names
4 .map((name) => {
5 return {
6 count: 1,
7 name: name
8 }
9 })
10 .reduce((a, b) => {
11 a[b.name] = (a[b.name] || 0) + b.count
12 return a
13 }, {})
14
15var duplicates = Object.keys(uniq).filter((a) => uniq[a] > 1)
16
17console.log(duplicates) // [ 'Nancy' ]
1let a = [1, 2, 3, 4, 2, 2, 4, 1, 5, 6]
2let b = [...new Set(a.sort().filter((o, i) => o !== undefined && a[i + 1] !== undefined && o === a[i + 1]))]
3
4// b is now [1, 2, 4]