Function definition
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); } }; Array.prototype.insert = function (index, item) { this.splice(index, 0, item); };
Usage:
myarray.remove(i); //Delete
//Update
myarray.remove(0);
myarray.insert(0,eventjson[0]);
//Insert
myarray.insert(0,eventjson[0]);
The above simple implementation of adding, deleting, modifying and checking the javascript js operation array is all the content shared by the editor. I hope it can give you a reference, and I also hope that everyone will support the PHP Chinese website.
For more javascript js operation array simple implementation of addition, deletion, modification and search related articles, please pay attention to the PHP Chinese website!