Array.prototype.remove = function (s, dust) {//If dust is ture, the deleted element is returned
if (dust) {
var dustarr = [];
for (var i = 0; i < this.length; i++) {
if (s = = This[i]) {
Dustarr.push (This.splice (i, 1) [0]);
}
}
return Dustarr;
}
for (var i = 0; i < this.length; i++) {
if (s = = This[i]) {
This.splice (i, 1);
}
}
return this;
}
Comments:
Splice () method adds/Deletes an item to/from the array, and then returns the item that was deleted.
Arrayobject.splice (index,howmany,item1,....., ItemX)
The splice () method deletes 0 or more elements starting at index and replaces the deleted elements with one or more values declared in the argument list.
This.splice (i, 1)[0] represents the deleted element
Array Object Properties
Property Description
Constructor Returns a reference to the array function that created this object.
Length Sets or returns the number of elements in the array.
Prototype gives you the ability to add properties and methods to objects.
Array Object method
Method Description
Concat () joins two or more arrays and returns the result.
Join () places all elements of an array into a string. element is delimited by the specified delimiter.
Pop () deletes and returns the last element of the array
Push () adds one or more elements to the end of the array and returns the new length.
Reverse () reverses the order of the elements in the array.
Shift () deletes and returns the first element of the array
Slice () returns the selected element from an existing array
Sort () sorts the elements of an array
Splice () deletes the element and adds a new element to the array.
Tosource () returns the source code of the object.
ToString () converts the array to a string and returns the result.
toLocaleString () converts the array to a local array and returns the result.
Unshift () adds one or more elements to the beginning of the array and returns the new length.
ValueOf () returns the original value of the array object
Pure js Add array Delete