美文网首页
数组两个参数之间交换位置 使用splice方法实现

数组两个参数之间交换位置 使用splice方法实现

作者: 小北酱丶 | 来源:发表于2020-03-23 10:13 被阅读0次
 //上移
    topStudent(index) {
      this.studentData.splice(
        index,
        1,
        ...this.studentData.splice(index - 1, 1, this.studentData[index])
      );
    },
    //下移
    bottomStudent(index) {
      this.studentData.splice(
        index + 1,
        1,
        ...this.studentData.splice(index, 1, this.studentData[index + 1])
      );
    },

相关文章

网友评论

      本文标题:数组两个参数之间交换位置 使用splice方法实现

      本文链接:https://www.haomeiwen.com/subject/zhofjhtx.html