// 原来的数组 var array = ["one", "two", "four"]; // splice(position, numberOfItemsToRemove, item) // 拼接函数(索引位置, 要删除元素的数量, 元素) array.splice(2, 0, "three"); array; // 现在数组是这个样子 ["one", "two", "three", "four"]
在JS数组指定位置插入元素
5 min read
// 原来的数组 var array = ["one", "two", "four"]; // splice(position, numberOfItemsToRemove, item) // 拼接函数(索引位置, 要删除元素的数量, 元素) array.splice(2, 0, "three"); array; // 现在数组是这个样子 ["one", "two", "three", "four"]