数组从大到小或从小到大排列

const arr = [3,2,4,6,5,8]
//从小到大
arr.sort((a,b) => a-b) //[2,3,4,5,6,8]
//从大到小
arr.sort((a,b) => b-a) //[8,6,5,4,3,2]

  

posted @ 2022-02-08 11:23  是你吗我笑了  阅读(128)  评论(0)    收藏  举报