Ascending And Descending Order
let arr = [3, 5, 4, 9, 2, 1];
arr.sort((a, b) => a - b); // for ascending order
console.log(arr);
arr.sort((a, b) => b - a); // for discending order
console.log(arr);
Output
[ 1, 2, 3, 4, 5, 9 ]
[ 9, 5, 4, 3, 2, 1 ]