Example Analysis of push function usage in javaScript
This example describes how to use the push function in javaScript. Share it with you for your reference. The specific analysis is as follows:
The push method in javaScript adds new elements to an array and returns the new Length Value of the array.
ArrayObj. push ([item1 [item2 [... [itemN])
Parameters
ArrayObj, required. An Array object.
Item, item2,... itemN, optional. The new element of the Array.
Description
The push method adds new elements in the order they appear. If one of the parameters is an array, the array will be added to the array as a single element. To merge two or more elements in an array, use the concat method.
?
| 1 2 3 4 5 6 7 8 9 |
Array. prototype. push = function (){ Var len = arguments. length; If (len> 0) for (var I = 0; I <len; I ++) this [this. length] = arguments [I]; Return this. length; } Var a = [1, 2, 4] A. push (5) Alert () Alert (a. push (6 )) |
I hope this article will help you design javascript programs.
Note <>: For more exciting tutorials, please pay attention to the help house programming