Skip to content
Related Articles

Related Articles

JavaScript Array push() Method

Improve Article
Save Article
  • Last Updated : 30 Nov, 2022
Improve Article
Save Article

The JavaScript Array push() Method is used to add one or more values to the end of the array. This method changes the length of the array by the number of elements added to the array.

Syntax:

arr.push(element1, elements2 ....., elementN]])

Parameters: This method contains as many numbers of parameters as the number of elements to be inserted into the array. 

Return value: This method returns the new length of the array after inserting the arguments into the array. 

Below is an example of the Array push() method.

Example 1: 

JavaScript




<script>
    function func() {
        var arr = ['GFG', 'gfg', 'g4g'];
          
        // Pushing the element into the array
        arr.push('GeeksforGeeks');
                console.log(arr);
      
    }
    func();
</script>

Output:

GFG,gfg,g4g,GeeksforGeeks

 Example 2: In this example, the function push() adds the numbers to the end of the array.

JavaScript




<script>
function func() {
    // Original array
    var arr = [34, 234, 567, 4];
  
    // Pushing the elements
    console.log(arr.push(23,45,56));
    console.log(arr);
}
func();
</script>

Output:

7
34,234,567,4,23,45,56

Example 3: In this example, the function push() adds the objects to the end of the array.

JavaScript




<script>
    function func() {
        // Original array
        var arr = [34, 234, 567, 4];
      
        // Pushing the elements
        console.log(arr.push('jacob',true,23.45));
        console.log(arr);
    }
    func();
</script>

Output:

7
34,234,567,4,jacob,true,23.45

We have a complete list of Javascript Array methods, to check those please go through this Javascript Array Complete reference article.

Supported Browsers: The browsers supported by the JavaScript Array push() method are listed below:

  • Google Chrome 1.0 and above
  • Microsoft Edge 12 and above
  • Mozilla Firefox 1.0 and above
  • Safari 1 and above
  • Opera 4 and above

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!