Home >>JavaScript Array Reference >JavaScript Array push() Method

JavaScript Array push() Method

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 Values

Parameter Description
item1, item2, ..., itemX It Required the elements to be added

Browser Support

Method Chrome Edge Firefox Safari Opera
push() 1.0 5.5 <1.0/td> Yes Yes
Here is an example of Array push() method:
<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>
Output:

Example 2:
<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>
Output: