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 counts = {};
2your_array.forEach(function(x) { counts[x] = (counts[x] || 0)+1; });
1var input = [1, 2, 3, 1, 3, 1];
2
3var duplicates = input.reduce(function(acc, el, i, arr) {
4 if (arr.indexOf(el) !== i && acc.indexOf(el) < 0) acc.push(el); return acc;
5}, []);
6
7document.write(duplicates); // = 1,3 (actual array == [1, 3])
1arr.reduce((b,c)=>((b[b.findIndex(d=>d.el===c)]||b[b.push({el:c,count:0})-1]).count++,b),[]);
1function doubleValues(array) {
2 var newArray = [];
3 array.forEach(function (el) { newArray.push(el, el); });
4 return newArray;
5}
6
7console.log(doubleValues([1,2,3]));