Nodejs Object Sort ksort(obj)

Here you can find the source of ksort(obj)

Method Source Code

function ksort(obj) {
    if (!obj || typeof (obj) != 'object') {
        return [];
    }//from   w  w w  . ja v  a2s. co m

    var keys = [], values = [];
    for (var i in obj) {
        keys.push(i);
    }

    keys.sort();
    for (var i = 0; i < keys.length; i++) {
        values.push(obj[keys[i]]);
    }

    return values;
}
;

Related

  1. sortByValue(toSort)
    function sortByValue(toSort) {
        var keys = Object.keys(toSort);
        keys.sort(function(a, b) {
            return toSort[a] < toSort[b] ? -1 : (toSort[a] === toSort[b] ? 0 : 1);
        });
        return keys;