JS数组splice拼接

语法

array.splice(start[, deleteCount[, item1[, item2[, ...]]]])

实例

const months = ['Jan', 'March', 'April', 'June'];
months.splice(1, 0, 'Feb');
// inserts at index 1
console.log(months);
// expected output: Array ["Jan", "Feb", "March", "April", "June"]

months.splice(4, 1, 'May');
// replaces 1 element at index 4
console.log(months);
// expected output: Array ["Jan", "Feb", "March", "April", "May"]

 




posted @ 2021-10-10 11:26  豆浆D  阅读(76)  评论(0编辑  收藏  举报