Example 1: count duplicates array js
uniqueCount = ["a","b","c","d","d","e","a","b","c","f","g","h","h","h","e","a"];
var count = {};
uniqueCount.forEach(function(i) { count[i] = (count[i]||0) + 1;});
console.log(count);
Example 2: how to get duplicate values from array in javascript
var array = [1, 2, 2, 3, 3, 4, 5, 6, 2, 3, 7, 8, 5, 22, 1, 2, 511, 12, 50, 22];
console.log([...new Set(
array.filter((value, index, self) => self.indexOf(value) !== index))]
);
Example 3: js find duplicates in array
const names = ['Mike', 'Matt', 'Nancy', 'Adam', 'Jenny', 'Nancy', 'Carl']
const count = names =>
names.reduce((a, b) => ({ ...a,
[b]: (a[b] || 0) + 1
}), {})
const duplicates = dict =>
Object.keys(dict).filter((a) => dict[a] > 1)
console.log(count(names))
console.log(duplicates(count(names)))
Example 4: javascript duplicate an array
let arr =["a","b","c"];
const duplicate = [...arr];
const duplicate = Array.from(arr);
Example 5: check for duplicates in array javascript
[1, 2, 3].every((e, i, a) => a.indexOf(e) === i)
[1, 2, 1].every((e, i, a) => a.indexOf(e) === i)
Example 6: js find duplicates in array
[1, 2, 2, 4, 3, 4].filter((e, i, a) => a.indexOf(e) !== i)