一、升序
var users = [
{
name: 'aaa',
age: 21
},
{
name: 'baa',
age: 18
},
{
name: 'abc',
age: 24
}
]
var sortByAge = users.sort(function(v1, v2){
return v1.age - v2.age
})
二、降序
var users = [
{
name: 'aaa',
age: 21
},
{
name: 'baa',
age: 18
},
{
name: 'abc',
age: 24
}
]
var sortByAge = users.sort(function(v1, v2){
return v2.age - v1.age
})
网友评论