JavaScript通过元素的索引号删除数组中的元素,如果要删除第3个元素,则使用removeByIndex(2)即可,JS数组从0开始
function removeByIndex(arr, index) { arr.splice(index, 1); } test = new Array(); test[0] = 'Apple'; test[1] = 'Ball'; test[2] = 'Cat'; test[3] = 'Dog'; // http://www.75271.com alert("Array before removing elements: "+test); removeByIndex(test, 2); alert("Array after removing elements: "+test);