class Utils { swapArray(arr, index1, index2) { arr[index1] = arr.splice(index2, 1, arr[index1])[0]; return arr; }, // 上移 將當前數組index索引與后面一個元素互換位置,向數組后面移動一位 moveUp(arr, index) { this.swapArray(arr, index, index - 1); }, // 下移 將當前數組index索引與前面一個元素互換位置,向數組前面移動一位 moveDown(arr, index) { this.swapArray(arr, index, index + 1); }, }