Quote from a question and answer in Baidu Know
For example array {1,2,3,4,5}
To delete 3 in the array to get {1,2,4,5}
js code:
<script type="text/javascript"> Array.pArray.prototype.indexOf = function(val) { //prototype Add attribute to the array for (var i = 0; i < this.length; i++) { //this refers to the number of array class elements if (this[i] == val) return i; //Elements in the array are equal to the passed parameter, i is the subscript, if there is, i will return} return -1; }; Array.prototype.remove = function(val) { //prototype Add attribute to the array var index = this.indexOf(val); //Call the index() function to get the return value of the search if (index > -1) { this.splice(index, 1); //Use the splice() function to delete the specified element. The splice() method is used to insert, delete or replace elements of the array} }; var array = [1, 2, 3, 4, 5]; array.remove(3);</script>in
Array.prototype.indexOf = function(val) { for (var i = 0; i < this.length; i++) { if (this[i] == val) return i; } return -1; };Array.prototype.remove = function(val) { var index = this.indexOf(val); if (index > -1) { this.splice(index, 1); } };The function is very practical. For arrays that need to be deleted, refer to array.remove(val); function, array is the deleted array name val is the specific content in the specified deleted array.
The above article js' implementation code for removing element implementations of specified values (not specified positions) from the array is all the content I share with you. I hope it can give you a reference and I hope you can support Wulin.com more.