JavaScript cuts off the array by setting an array of Length attributes that shorten the length of the array. If you use the Delete operator to delete an array element, although the element becomes undefined, the length of the array does not change. Two methods of deleting elements, array lengths also change.
/ * * Method: Array.Remove (DX) * Function: Delete array elements. * Parameters: DX Delete elements' subscript. * Return: Modify array in the original number group * /
// often use through traversal, reconstruction array .array.prototype.remove = function (dx) {if (ISNAN (DX) || DX> this.length) {Return False;} for (var i = 0, n = 0; I / * * Method: Array.Baoremove (DX) * Function: Delete array elements. * Parameters: DX Delete elements' subscript. * Return: Modify an array in the original number group. * /// We can also use splice. Array.Prototype.Baoremove = function (DX) {IF (isnan (dx) || DX> this.length) {Return False;} this.splice (dx, 1);} b = ['1', '2' , '3', '4', '5']; Alert ("Elements:" B "/ NLENGTH:" B.Length); B.Baoremove (1); // Delete Elements 1 Element 1 Alert ("Elements:" B "/ NLENGTH:" B.LENGTH); script>