1let strArray = [ "q", "w", "w", "w", "e", "i", "u", "r"];
2let findDuplicates = arr => arr.filter((item, index) => arr.indexOf(item) != index)
3
4console.log(findDuplicates(strArray)) // All duplicates
5console.log([...new Set(findDuplicates(strArray))]) // Unique duplicates
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);
1let arr =["a","b","c"];
2// ES6 way
3const duplicate = [...arr];
4
5// older method
6const duplicate = Array.from(arr);
1function hasDuplicates(array) {
2 return (new Set(array)).size !== array.length;
3}
1var counts = {};
2your_array.forEach(function(x) { counts[x] = (counts[x] || 0)+1; });
1[1, 2, 3].every((e, i, a) => a.indexOf(e) === i) // true
2
3[1, 2, 1].every((e, i, a) => a.indexOf(e) === i) // false
4