1、根据id值 从小到大排序
//模拟数据 var list = [{"id" : 5, "name": "小明", "age" : 5}, {"id" : 2, "name": "小红", "age" : 12}, {"id" : 3, "name": "小花", "age" : 8}, {"id" : 1, "name": "小白", "age" :24}, {"id" : 4, "name": "小黑", "age" : 10}]; //根据id值 从小到大排序 function sortId(a, b) { return a.id - b.id; } list.sort(sortId);
2、根据age值 从大到小排序
//根据age 从大到小排列 function sortUseAge(a, b) { return b.age - a.age; } list.sort(sortUseAge);
参考:https://blog.csdn.net/qq_40015157/article/details/110817184
标签:name,根据,对象,age,list,js,值来,排序,id From: https://www.cnblogs.com/wongzzh/p/16623457.html