This article describes how to use jquery push. You can add one or more elements to the end of the array and return a new length. For more information, see
Definition and usage of push
The push () method can add one or more elements to the end of an array and return a new length.
Syntax
ArrayObject. push (newelement1, newelement2,..., newelementX)
Parameter description
Newelement1 is required. The first element to be added to the array.
Newelement2 is optional. The second element to be added to the array.
NewelementX is optional. You can add multiple elements.
Return Value
Adds the specified value to the new length after the array.
Description
The push () method can add its Parameter order to the end of arrayObject. It directly modifies the arrayObject instead of creating a new array. The push () and pop () methods use the advanced post-stack functions provided by arrays.
Tips and comments
Note: This method will change the length of the array.
Tip: to add one or more elements at the beginning of an array, use the unshift () method.
Instance
In this example, we will create an array and add an element to change its length:
The Code is as follows:
Var arr = new Array (3 );
Arr [0] = "George ";
Arr [1] = "John ";
Arr [2] = "Thomas ";
Document. write (arr + "") document. write (arr. push ("James") + "") document. write (arr );
Output:
George, John, Thomas
4
George, John, Thomas, James
One usage on the Internet:
The Code is as follows:
$ (Function (){
Var buf = [];
Buf. push ('