$(function(){
$.get("http://localhost:3000/number",function(data){
console.log(data)
var data=data
var a=data.slice(0,4)//截取数组的前4项
b=data.slice(-4)//截取数组的后4项
var c = a.concat(b) //合并2个截取数组生产一个新数组
c.sort(compare('AMPLITUDE')); //调用函数给新数组以AMPLITUDE排序
console.log(c)
})
})
var student = [{"name":"lisi","age":18,"sex":"male"},
{"name":"zhangsan","age":17,"sex":"female"},
{"name":"wangwu","age":21,"sex":"shemale"}];
student.sort(compare("age"));
console.dir(student);
function compare(protoTypeName) {
return function(object1,object2){
var val1 = object1[protoTypeName];
var val2 = object2[protoTypeName];
if(val1<val2){
return -1;
}else if(val1>val2){
return 1;
}else{
return 0;
}
}
}
</script>
网友评论