let arr = ['132','qwedd','q','2r','qwd'];
arr = arr.sort(function(a,b){
return a.length-b.length;
})
//输出 ["q", "2r", "132", "qwd", "qwedd"]
//倒叙
let arr = ['132','qwedd','q','2r','qwd'];
arr = arr.sort(function(a,b){
return b.length-a.length;
})
js数组 按照每一项的字符串长度进行排序
最新推荐文章于 2023-02-20 17:14:13 发布