What is the use of the push() method in JavaScript Arrays ?
Last Updated :
31 Jan, 2024
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);
|
Share your thoughts in the comments
Please Login to comment...