var numbers = [1, 10, 2, 20, 3, 30];
numbers.sort(function compare(a, b) {
return a - b;
});
console.log(numbers); // [1,2,3,10,20,30]
또는
arr.sort((a, b) => a - b);
var numbers = [1, 10, 2, 20, 3, 30];
numbers.sort(function compare(a, b) {
return b - a;
});
console.log(numbers); // [30,20,10,3,2,1]