Array push() Method - Javascript Array

Javascript examples for Array:push

Description

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.

Syntax

array.push(item1, item2, ..., itemX);

Parameter Values

ParameterDescription
item1, item2, ..., itemX Required. The item(s) to add to the array

Return Value:

A Number, representing the new length of the array

The following code shows how to Add more than one item:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials