Okay, I've only figured out how to get one mode out of the array.. But I want to get 2, 3 or more if they occur the same amount of times. This is the code:
var frequency = {};  // array of frequency.
var maxFreq = 0;  // holds the max frequency.
for (var i in array) {
    frequency[array[i]] = (frequency[array[i]] || 0) + 1; // increment frequency.
    if (frequency[array[i]] > maxFreq) { // is this frequency > max so far ?
        maxFreq = frequency[array[i]];  // update max.
        mode = array[i];          // update result.
    }
}
So right now, if I've got a array = [3, 8, 3, 6, 1, 2, 9];
I get mode = 3;
But what I'm looking for is if array = [3, 6, 1, 9, 2, 3, 6, 6, 3, 1, -8, 7];
I want to get the mode = 3, 6;
 
     
     
     
    