js sorted according to the attributes array of objects

 

 

function compare(property,desc) {
    return function (a, b) {
        var value1 = a[property];
        var value2 = b[property];
        if(desc==true){
            // 升序排列
            return value1 - value2;
        } The else {
             // descending 
            return value2 - VALUE1;
        }
    }
}


mergeArr1(data).sort(compare("carNum",false))

 

Guess you like

Origin www.cnblogs.com/xhrr/p/12303134.html