Possible Duplicate:
Sorting JavaScript Object by property value
Sort JavaScript object by key
I've written a function called frequency()
that takes an Array, counts the number of times a string is found within it, and then returns an object based on these results.
Code:
var array = ["Diesel","Asos","Diesel","Paul Smith"];
function frequency(array) {
var frequency = {}, value;
for(var i = 0; i < array.length; i++) {
value = array[i];
if(value in frequency)
frequency[value]++;
else
frequency[value] = 1;
}
return frequency;
}
ordered = frequency(array);
Sample output:
{"Asos":1,"Diesel":2,"Paul Smith":1}
How can I now sort this outputted object based on the counted frequency value?