Skip to content

Instantly share code, notes, and snippets.

@sofish
Created January 4, 2012 08:11
Show Gist options
  • Select an option

  • Save sofish/1559059 to your computer and use it in GitHub Desktop.

Select an option

Save sofish/1559059 to your computer and use it in GitHub Desktop.
理解的 hash
var obj = {
1:'person1',
2:'person2',
5:'person3',
9:'person4',
12:'person5',
9:'person6'
},
tmpArray = [];
for(key in obj){
tmpArray.push(key);
}
tmpArray = tmpArray.sort(function(a,b){
return b-a
});
for(var i=0, len=tmpArray.length; i<len;i++){
console.log('#' + i + ': ', obj[+tmpArray[i]], ' score: ' + tmpArray[i]);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment