Current location - Education and Training Encyclopedia - Resume - How does js compare the lengths of arrays in objects?
How does js compare the lengths of arrays in objects?
//User-defined sorting function

Function? SortFun (props? ,? rev){

//Sort by attribute, and decide ascending or descending order according to Rev.

If (rev? ===? Undefined) {

rev? = 1;

} something else? {

rev? =(rev)? 1? :? - 1;

}

Return? Function? (a,b){

Jean? val 1? =? A [prop];

Jean? val2? =? b[prop];

if(val 1? & lt? val2){

Return? rev? *? - 1;

}

if(val 1? & gt? val2){

Return? rev? *? 1;

}

Return? 0;

}

}

Function? clickFun()? {

var? First grade? =? {

Class one:? ['language core',? Yang Wenli? Geng Yu Zhen',? Can HTC',? Sophora japonica'],

Class two:? 【' Ji Jiayun',? Bai Qiu'? Dai Yong e? Liao junfeng],

Class 3:? ['Ji Jingying',? Xia Han' Murong Tianqing' Shi Hongwen'? Sui Yueyong'? Laurel's clothes? Yan Yuhua']

};

var? For example? =[];

//instanceof? rank

for(var? Keys? Are you online? Grade one) {

var? arr? =? First grade [emphasis];

If (? arr? instanceof? Array? ) {//Determines whether the value of this property is an array.

example.push({"key ":? The key? " len ":? arr.length})。 //Put it in the example to facilitate sorting later.

}

}

//Call the sort method to sort.

example.sort(sortFun('len ',? false)); //false is descending.

debugger

Console.log (example [0]). Key); //in descending order, so the first one is the most.

}