// var obj =
var persons = [
{name:"lily1",sex:"女",age:18},
{name:"lily2",sex:"女",age:19},
{name:"lily3",sex:"女",age:11},
{name:"lily4",sex:"女",age:28},
{name:"lily5",sex:"女",age:22},
]
//请对数组persons进行按照年龄升序排序
persons.sort(function (a,b) {
if (a.age>b.age) {
return 1;
}else if(a.age<b.age){
return -1;
}else{
return 0;
}
})
console.log(persons);
网友评论