JavaScript uses loops and splits to replace and delete element instances, while javascript instances
Elements can be replaced and deleted using loops and splits. It has been tested to be simple but practical, and is especially suitable for new users.
<! DOCTYPE>
Ie8 does not support indexOf or splice
JavaScript element replacement
The following line has a problem:
For (I = 0; I <count; I ++)
Modify this line as follows:
For (I = count-1; I> = 0; I --)
Don't be confused. After modification, the test will find that it is correct. Because your original statement is equivalent to deleting input, When you modify two, the I loop value has exceeded the valid range.
In javascript, how does one Delete the element of a value in an array?
Test = newArray (); Array. prototype. removeByValue = function (val) {for (vari = 0; I <this. length; I ++) {if (this [I] = val) {this. splice (I, 1); break ;}} test [0] = 'apple'; test [1] = 'ball'; test [2] = 'cat '; test [3] = 'Dog'; alert ("Array before removing elements:" + test); test. removeByValue ('cat'); alert ("Array after removing elements:" + test );
Reference: hi.baidu.com/...1.html