Home >Web Front-end >JS Tutorial >JavaScript push usage guide_Basic knowledge
The
push() method adds one or more elements to the end of the array and returns the new length. The return value is the new length after adding the specified value to the array.
Syntax: arrayObject.push(newelement1,newelement2,....,newelementX)
Parameter newelement1, required. The first element to be added to the array.
Parameter newelement2, optional. The second element to be added to the array.
Parameter newelementX, optional. Multiple elements can be added.
The push() method adds its parameters sequentially to the end of arrayObject. It directly modifies the arrayObject instead of creating a new array. The push() method and pop() method use the first-in-last-pop function provided by the array. This method changes the length of the array.
Example: