JavaScript通过元素索引号删除数组中对应元素的方法
本文实例讲述了JavaScript通过元素索引号删除数组中对应元素的方法。分享给大家供大家参考。具体分析如下:
JavaScript通过元素的索引号删除数组中的元素,如果要删除第3个元素,则使用RemoveValByIndex(2)即可,JS数组从0开始
functionRemoveValByIndex(arr,index){ arr.splice(index,1); } test=newArray(); test[0]='Apple'; test[1]='Ball'; test[2]='Cat'; test[3]='Dog'; alert("Arraybeforeremovingelements:"+test); RemoveValByIndex(test,2); alert("Arrayafterremovingelements:"+test);
希望本文所述对大家的javascript程序设计有所帮助。