My problem is similar to the question asked here: Extracting the most duplicate value from an array in JavaScript (with jQuery)
I tried the code provided, but it only returns one value, which is 200.
var arr = [100,100,200,200,200,300,300,300,400,400,400];
var counts = {}, max = 0, res;
for (var v in arr) {
counts[arr[v]] = (counts[arr[v]] || 0) + 1;
if (counts[arr[v]] > max) {
max = counts[arr[v]];
res = arr[v];
}
}
console.log(res + " occurs " + counts[res] + " times");
Please help me modify the code to return multiple values, not just one...
The expected result should be: 200, 300, 400. Please assist, thank you!