标签:javascript 索引 数组 插入 prototype
原文链接: Array: Insert an Item at a Specific Index with JavaScript// 原来的数组 var array = ["one", "two", "four"]; // splice(position, numberOfItemsToRemove, item) // 拼接函数(索引位置, 要删除元素的数量, 元素) array.splice(2, 0, "three"); array; // 现在数组是这个样子 ["one", "two", "three", "four"]
Array.prototype.insert = function (index, item) { this.splice(index, 0, item); };
var nums = ["one", "two", "four"]; nums.insert(2, ‘three‘); // 注意数组索引, [0,1,2..] array // ["one", "two", "three", "four"]
标签:javascript 索引 数组 插入 prototype
原文地址:http://blog.csdn.net/renfufei/article/details/38143947