This article describes how to delete a specified value element from an array by using JavaScript. The example shows two common javascript methods to operate on specified elements in an array, which is of reference value, for more information about how to use JavaScript to delete a specified element from an array, see the following example. Share it with you for your reference. The specific analysis is as follows:
The following code uses two methods to delete Array elements. The first is to define a separate function, and the second is to define a removeByValue method for the Array object. the call is very simple.
Define the removeByValue function to delete an element.
Function removeByValue (arr, val) {for (var I = 0; IAdding corresponding methods to the array object makes it easier to call. you can directly call the removeByValue method of the array to delete the specified element.
Array. prototype. removeByValue = function (val) {for (var I = 0; I
I hope this article will help you design javascript programs.