Javascript examples for Array:push
The push() method adds new items to the end of an array, and returns the new length.
This method changes the length of the array.
array.push(item1, item2, ..., itemX);
Parameter | Description |
---|---|
item1, item2, ..., itemX | Required. The item(s) to add to the array |
A Number, representing the new length of the array
The following code shows how to Add more than one item:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> var fruits = ["a","b","c","d","e"]; document.getElementById("demo").innerHTML = fruits; function myFunction() {//from w ww . ja va 2 s . c o m fruits.push("Kiwi", "Lemon", "Pineapple"); document.getElementById("demo").innerHTML = fruits; } </script> </body> </html>