1.splice
splice(index, num)
index: 下标
num: 删除的数量
@return 删除的元素
原来的数组会被修改
删掉第三个元素
1 | let dataSource = ["a", "b", "c"] |
在for 循环使用
比如要依次删除 dataSource中的元素
1 | let dataSource = ["a", "b", "c"] |
2.slice
2.slice(startIndex, endIndex)
startIndex: 开始下标 必填
endIndex: 结束下标(不包含这个元素) 非必填
@return 截取的元素
原来的数组不会被修改
1 | let dataSource = ["a", "b", "c"] |