The Wayback Machine - https://web.archive.org/web/20240118181352/https://www.geeksforgeeks.org/javascript-array-push-method/
Open In App
Related Articles

JavaScript Array push() Method

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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(element0, element1, … , 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. 

Example 1: In this example, we are adding “GeeksforGeeks” to the array.

JavaScript




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


Output

[ 'GFG', 'gfg', 'g4g', 'GeeksforGeeks' ]

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

JavaScript




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


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




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


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:

  • 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.


Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore.
Last Updated : 07 Dec, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads
Complete Tutorials