wqh 2020-05-25 17:11:20

简单的数组排序

let a = [ {index:9},{index:5},{index:3},{index:4},{index:411},{index:1}]
//根据对象数组中的某一个值进行排序,如当前数组的index;
a.sort((a,b)=>a.index - b.index);  //小->大
a.sort((a,b)=>b.index - a.index);  //大->小
console.log(a);

评论

ホーム - Wiki
Copyright © 2011-2024 iteam. Current version is 2.137.1. UTC+08:00, 2024-11-15 00:39
浙ICP备14020137号-1 $お客様$