const arr = [8, 2, 5, 3, 0] arr.sort((a, b) => { // -1 sorts up if (a > b) return -1 // 1 sorts down else if (a < b) return 1 // 0 keeps position return 0 }) console.log(arr) // [8, 5, 3, 2, 0]