数组中插入一个元素

2022-04-11  本文已影响0人  sweetBoy_9126
  1. 数组两项元素交换位置
const exchange = (dragIndex, hoverIndex) => {
  arr[dragIndex] = arr.splice(hoverIndex, 1, arr[dragIndex])[0]
}
  1. 把数组里的某一项移动到某一位置(常见拖拽的时候drop函数里用)
const exchange = (dragIndex, dropIndex) => {
    const copyLists = [...arr];
    const dragData = copyLists.splice(dragIndex, 1);
    const effticeDropIndex = dragIndex < dropIndex ? (dropIndex - 1) : dropIndex
    copyLists.splice(effticeDropIndex, 0, dragData[0]);
}
上一篇 下一篇

猜你喜欢

热点阅读