Last updated 4 years ago
Was this helpful?
const arr = [2, 5, 3]; arr.sort((a, b) => a - b); // [2, 3, 5]
會改變原來的 Array,如果不想改變到原本 Array 可用以下:
const sorted = [...arr].sort(); // 或是 const sorted = arr.slice(0).sort();