对象数组按属性排序
var str=[
{title:"a",value:50},
{title:"b",value:20},
{title:"c",value:40},
{title:"d",value:30},
];
function compare(key){
return function(value1,value2){
var val1=value1[key];
var val2=value2[key];
return val1-val2;
}
}
str.sort(compare('value'));
console.log(str);