How to sort a numeric array in descending order with JavaScript

1 Answer

0 votes
let arr = [4, 8, 2, 11, 9, 7]; 
       
arr.sort(function(a, b){return b - a}); 
   
console.log(arr);
 
 
/*
run:
 
[ 11, 9, 8, 7, 4, 2 ]
 
*/

 



answered May 20, 2020 by avibootz
edited Feb 26, 2025 by avibootz

Related questions

1 answer 81 views
1 answer 79 views
3 answers 100 views
3 answers 102 views
1 answer 84 views
...