For example, array {1,2,3,4,5}
To delete the 3 inside the array to get {1,2,4,5}
<script type= "Text/javascript" >Array.prototype.indexOf=function(Val) {//prototype adding properties to an array for(vari = 0; I < This. length; i++) {//This is the number of array class elements that refer to an array, this.length if( This[I] = = val)returnI//The elements in the array are equal to the parameters passed in, I is the subscript, and if present, I return } return-1; }; Array.prototype.remove=function(Val) {//prototype adding properties to an array varindex = This. IndexOf (Val);//call the index () function to get the return value of the lookup if(Index >-1) { This. Splice (index, 1);//Use the splice () function to delete a specified element, the splice () method for inserting, deleting, or replacing an element of an array } }; varArray = [1, 2, 3, 4, 5]; Array.remove (3);</script>
A useful code
Array.prototype.indexOf =function(val) { for(vari = 0; I < This. length; i++) { if( This[I] = = val)returni; } return-1; }; Array.prototype.remove=function(val) {varindex = This. IndexOf (Val); if(Index >-1) { This. Splice (Index, 1); } };
For an array that needs to be deleted, reference Array.remove (val); The function can be an array of the names of the deleted arrays Val is the specific content in the specified deleted array
Go: JavaScript removes an element from an array of specified values (not a specified position)