Examples as: below:
Copy code code as follows:
/**
* Delete the array elements through the value
*
* @param Mixed Value elemental value
* @Return array
*/
Array.prototype.deletevalue = function (value) {
var I = 0;
for (I in this) {
if (this [i] == value) break;
}
Return this.slice (0, i) .concat (this.slice (PARSEINT (i, 10) + 1));
}
// Example
var test = new array (1,5,3,4,2);
// Output 5
console.log (test.length);
// Delete the element with a value of 4
test = test.deletevalue (4);
// Output [1, 5, 3, 2]
console.log (test);
// Output 4
console.log (test.length);
/**
* Delete array elements through indexes
*
* @param int int index index
* @Return array
*/
Array.prototype.DeleteIndex = Function (index) {
Return this.slice (0, index) .concat (this.slice (PARSEINT (Index, 10) + 1));
}
// Example
var test = new array (1,5,3,4,2);
// Output 5
console.log (test.length);
// Delete the element with indexing 1
test = test.deleteIndex (1);
// Output [1, 3, 4, 2]
console.log (test);
// Output 4
console.log (test.length);