How to use Unshift() Method In Javascript
The unshift()
method is used to add one or more elements to the beginning of an array.
Example: This code example uses unshift() method to add the elements into an array.
Javascript
const myArray = [4, 5, 6]; myArray.unshift(3); console.log(myArray); myArray.unshift(1, 2); console.log(myArray); |
[ 3, 4, 5, 6 ] [ 1, 2, 3, 4, 5, 6 ]
Add Elements to a JavaScript Array
JavaScript Arrays are a fundamental data structure in JavaScript, providing a flexible way to store and manage collections of values. Add elements to a JavaScript Array is a common operation in programming. There are different methods to add elements to the JavaScript array, which are described below