Open In App

What is the use of the push() method in JavaScript Arrays ?

Last Updated : 31 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In JavaScript, the push() method is used to add one or more elements to the end of an array. It modifies the original array by appending the specified values. This can be particularly useful when you want to dynamically expand the size of an array or simply add new elements to the existing list.

Example: Here, we are pushing newElement in myArray.

Javascript




let myArray = [1, 2, 3];
let newElement = 4;
 
myArray.push(newElement);
 
console.log(myArray); // Output: [1, 2, 3, 4]


Output

[ 1, 2, 3, 4 ]

Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads