JS对象数组排序

利用数组api ——> sort来进行排序

var person = [
  {name:"Rom",age:12},
  {name:"Bob",age:22},
  {name:"Ma",age:5},
  {name:"Tony",age:25}
]

person.sort((a,b)
=>{ return a.age-b.age})//升序 person.sort((a,b)=>{ return b.age-a.age})//降序

 

posted @ 2021-03-23 18:07  smil、梵音  阅读(36)  评论(0编辑  收藏  举报