Home >>JavaScript Array Reference >JavaScript Array push() Method
JavaScript array push() method is used to appends the given elements to the end of the given array and changes the length of the original array by the number of elements added to the array.
Syntax:array.push(item1, item2, ..., itemX)
Parameter | Description |
---|---|
item1, item2, ..., itemX | It Required the elements to be added |
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
push() | 1.0 | 5.5 | <1.0/td> | Yes | Yes |
<html> <body> <button onclick="myPushmethod()">Click me</button> <p id="push"></p> <script> var y = ["10", "15", "25", "35"]; document.getElementById("push").innerHTML = y; function myPushmethod() { y.push("45"); document.getElementById("push").innerHTML = y; } </script> </body> </html>
<html> <body> <script> function arrPush() { var z = [10, 20, 30, 40, 50]; document.write(z.push('phptpoint',true,55.67)); document.write("<br>"); document.write(z); } arrPush(); </script> </body> </html>