js删除数组指定索引元素
const arr = [1,2,3,4]
delete arr[1]
console.log(arr) // 1,3,4
js对数组调整顺序调整
let arr = [1,2,3,4,5,6]
const swapArray = (index1: number, index2: number) => {
arr[index1] = arr.splice(index2, 1, arr[index1])[0];
console.log("新的数组",arr)
}
// 向上移动
const idnex = 3
if (index !== 0) {
swapArray(index, index-1);
} else {
console.log('已经处于置顶,无法上移');
}
//向下移动
if (index+1 !== arr.length) {
swapArray(index, index+1);
} else {
console.log('已经处于置底,无法下移');
}