typescript 数组排序
作者:互联网
let array=[
{name:"张三",age:18},
{name:"王五",age:28},
{name:"Tom",age:22},
{name:"Jack",age:19},
{name:"李明",age:35},
{name:"小兰",age:20}
]
array.sort((a,b)=>{return `${a.name}`.localeCompare(`${b.name}`)}) ; //按名字降序排序
array.sort((a,b)=>{return a.age-b.age}) ; //按age降序排序
标签:sort,typescript,name,age,数组,array,排序,降序 来源: https://www.cnblogs.com/boye169/p/16194637.html