SOURCE

let arr = [5, 4, 3, 2, 1];
for (let i = 0; i < arr.length - 1; i++) {
    for (let j = 0; j < arr.length - 1 - i; j++) {
        [arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
    }
}
console.log(arr)
console 命令行工具 X clear

                    
>
console