How to sort an array in reverse order with Node.js

1 Answer

0 votes
let arr = [3, 7, 4, 5, 9, 1, 2];

arr = [...arr].sort((a, b) => b - a);

console.log(arr);
 
   
   
   
   
/*
run:
   
[9, 7, 5, 4, 3, 2, 1]

   
*/

 



answered Apr 24, 2022 by avibootz

Related questions

...