語法格式:splice(index, len, [item])
可以用來替換/刪除/添加數(shù)組內(nèi)某一個值或幾個值,該方法會改變初始數(shù)組。
- index:數(shù)組開始下標(biāo)
- len:替換/刪除的長度
- item:替換的值,為刪除時item為空
刪除:
let arr = ['1','2','3','4'];
arr.splice(0,2);
console.log(arr.toString());
//3,4
替換:文章來源:http://www.zghlxwxcb.cn/news/detail-692049.html
let arr = ['1','2','3','4'];
arr.splice(0,2,['5','6','7']);
console.log(arr.toString());
//5,6,7,3,4
新增:文章來源地址http://www.zghlxwxcb.cn/news/detail-692049.html
let arr = ['1','2','3','4'];
arr.splice(0,0,['5','6','7']);
console.log(arr.toString());
//5,6,7,1,2,3,4,
到了這里,關(guān)于Vue splice方法使用的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!