// The initial array we want to count occurences var initial = [5, 5, 5, 2, 2, 2, 2, 2, 9, 4]; // The count array asked for var count = Array.from(new Set(initial)).map(val => initial.filter(v => v === val).length); // Outputs [ 3, 5, 1, 1 ]