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

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 ]



Reffered: https://www.geeksforgeeks.org


JavaScript

Related
What is the use of fill() method in JavaScript Arrays ? What is the use of fill() method in JavaScript Arrays ?
What is the use of the every() method in JavaScript Arrays ? What is the use of the every() method in JavaScript Arrays ?
How to Convert an Array to a String in JavaScript ? How to Convert an Array to a String in JavaScript ?
What is the use of the Array.of() method in JavaScript ? What is the use of the Array.of() method in JavaScript ?
What is a Sparse Array in JavaScript ? What is a Sparse Array in JavaScript ?

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
13