[Solved] Browse through an array for a specific amount of values


Please try this code:

var arr = ['a','a','b','b','b','c'];

var numberOfOccurrences = {};

arr.forEach(function (item) {
    numberOfOccurrences[item] = (numberOfOccurrences[item] || 0) + 1;
});

var duplicates = Object.keys(numberOfOccurrences).filter(function (item) { return numberOfOccurrences[item] === 2 });

console.log(duplicates);

3

solved Browse through an array for a specific amount of values