直接上代码
var arr=[{name:"a",age:18},{name:"b",age:13},{name:"c",age:21}]; arr.sort((a,b)=>{return a.age-b.age});//升序 arr.sort((a,b)=>{return b.age-a.age});//降序
微信扫码查看本文
直接上代码
var arr=[{name:"a",age:18},{name:"b",age:13},{name:"c",age:21}]; arr.sort((a,b)=>{return a.age-b.age});//升序 arr.sort((a,b)=>{return b.age-a.age});//降序
发表评论