我们知道map是无序的,想对map进行排序,就得进行相应的转化。

function sortMap(){
    var hashmap = {"2":"javascript","1":"java","5":"golang","8":"lua"};
    console.log(hashmap);
    var keys = new Array();
    for(var key in hashmap){
            keys.push(key);
    }
    keys.sort(function(a,b){return b-a});
    for(var index in keys){
        var key = keys[index];
        console.log(hashmap[key]);
    }
}