当前位置:网站首页>Array object sorting

Array object sorting

2022-07-07 11:09:00 Have a good time I

Generally, the back end returns an array object , Let the front end sort . There are many ways :
 Insert picture description here
As shown in the above figure, an array object is returned , In order . The interface returns as follows , Let the back end add one order Field , according to order Field to sort .
 Insert picture description here

Write down the simplest one today :
Using the array api ——> sort To sort

var person = [{
    name:"Jack",age:12},{
    name:"Bob",age:22},{
    name:"Rose",age:5},{
    name:"Tony",age:25}]
 
person.sort((a,b)=>{
     return a.age-b.age})// Ascending 
 
person.sort((a,b)=>{
     return b.age-a.age})// Descending 
原网站

版权声明
本文为[Have a good time I]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202130619539259.html