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);

评论

trang chủ - Wiki
Copyright © 2011-2024 iteam. Current version is 2.137.3. UTC+08:00, 2024-11-28 14:41
浙ICP备14020137号-1 $bản đồ khách truy cập$