Use unshift. It's like push, except it adds elements to the beginning of the array instead of the end.

  • unshift/push - add an element to the beginning/end of an array
  • shift/pop - remove and return the first/last element of an array

A simple diagram...

unshift -> [array] <- push
shift   <- [array] -> pop

and chart:

  add remove start end
push X X
pop X X
unshift X X
shift X X

Check out the MDN Array documentation. Virtually every language that has the ability to push/pop elements from an array will also have the ability to unshift/shift (sometimes called push_front/pop_front) elements, you should never have to implement these yourself.


As pointed out in the comments, if you want to avoid mutating your original array, you can use concat, which concatenates two or more arrays together. You can use this to functionally push a single element onto the front or back of an existing array; to do so, you need to turn the new element into a single element array:

const array = [3, 2, 1]

const newFirstElement = 4

const newArray = [newFirstElement].concat(array) // [ 4, 3, 2, 1 ]

console.log(newArray);

concat can also append items. The arguments to concat can be of any type; they are implicitly wrapped in a single-element array, if they are not already an array:

const array = [3, 2, 1]

const newLastElement = 0

// Both of these lines are equivalent:
const newArray1 = array.concat(newLastElement) // [ 3, 2, 1, 0 ]
const newArray2 = array.concat([newLastElement]) // [ 3, 2, 1, 0 ]

console.log(newArray1);
console.log(newArray2);

Answer from user229044 on Stack Overflow
Top answer
1 of 12
4058

Use unshift. It's like push, except it adds elements to the beginning of the array instead of the end.

  • unshift/push - add an element to the beginning/end of an array
  • shift/pop - remove and return the first/last element of an array

A simple diagram...

unshift -> [array] <- push
shift   <- [array] -> pop

and chart:

  add remove start end
push X X
pop X X
unshift X X
shift X X

Check out the MDN Array documentation. Virtually every language that has the ability to push/pop elements from an array will also have the ability to unshift/shift (sometimes called push_front/pop_front) elements, you should never have to implement these yourself.


As pointed out in the comments, if you want to avoid mutating your original array, you can use concat, which concatenates two or more arrays together. You can use this to functionally push a single element onto the front or back of an existing array; to do so, you need to turn the new element into a single element array:

const array = [3, 2, 1]

const newFirstElement = 4

const newArray = [newFirstElement].concat(array) // [ 4, 3, 2, 1 ]

console.log(newArray);

concat can also append items. The arguments to concat can be of any type; they are implicitly wrapped in a single-element array, if they are not already an array:

const array = [3, 2, 1]

const newLastElement = 0

// Both of these lines are equivalent:
const newArray1 = array.concat(newLastElement) // [ 3, 2, 1, 0 ]
const newArray2 = array.concat([newLastElement]) // [ 3, 2, 1, 0 ]

console.log(newArray1);
console.log(newArray2);

2 of 12
1761

var a = [23, 45, 12, 67];
a.unshift(34);
console.log(a); // [34, 23, 45, 12, 67]

🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › unshift
Array.prototype.unshift() - JavaScript | MDN
const arr = [1, 2]; arr.unshift(0); ... arr.unshift([-7, -6], [-5]); // the new array length is 8 // arr is [ [-7, -6], [-5], [-4, -3], -2, -1, 0, 1, 2 ] The unshift() method reads the length property of this....
People also ask

What is the fastest way to add an element to the beginning of a JavaScript array?
For arrays with fewer than 10,000 elements, unshift() provides the fastest performance when mutation is acceptable. For immutable operations, the spread operator offers the best combination of performance and readability. For very large arrays (100,000+ elements), consider using concat() or building a new array with a loop.
🌐
sencha.com
sencha.com › home › blog › how to add elements to the beginning of an array in javascript (2026 guide)
How to Add Elements to the Beginning of an Array in JavaScript ...
Does unshift() modify the original array?
Yes, unshift() modifies the original array in place. It adds elements to the beginning and shifts existing elements to higher indices. If you need to preserve the original array, use the spread operator or concat() to create a new array instead.
🌐
sencha.com
sencha.com › home › blog › how to add elements to the beginning of an array in javascript (2026 guide)
How to Add Elements to the Beginning of an Array in JavaScript ...
What is the difference between push() and unshift()?
push() adds elements to the end of an array, while unshift() adds elements to the beginning. Both methods mutate the original array and return the new length.
🌐
sencha.com
sencha.com › home › blog › how to add elements to the beginning of an array in javascript (2026 guide)
How to Add Elements to the Beginning of an Array in JavaScript ...
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › add-new-elements-at-the-beginning-of-an-array-using-javascript
Insert at the Beginning of an Array in JavaScript - GeeksforGeeks
July 11, 2025 - This method is similar to the push() method but it adds an element at the beginning of the array. ... The array.splice method is used to modify the content of the array. we give the start, end the value as a parameter to the method so that it helps us to add the value in between the given start and end index. ... The Spread operator allows an iterable to expand in places where 0+ arguments are expected. It is mostly used in the variable array where there is more than 1 value is expected. ... The JavaScript Array concat() Method is used to merge two or more arrays together.
🌐
W3Schools
w3schools.com › jsref › jsref_unshift.asp
JavaScript Array unshift() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST ... Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
🌐
Sencha
sencha.com › home › blog › how to add elements to the beginning of an array in javascript (2026 guide)
How to Add Elements to the Beginning of an Array in JavaScript (2026 Guide)
March 14, 2024 - Sencha Ext JS provides built-in store management with array prepending capabilities: // Creating a store with initial data const store = Ext.create('Ext.data.Store', { fields: ['id', 'name', 'priority'], data: [ { id: 2, name: 'Review code', priority: 'medium' }, { id: 3, name: 'Write tests', priority: 'low' } ] }); // Prepending a record using insert at index 0 store.insert(0, { id: 1, name: 'Critical bug fix', priority: 'high' }); // For grid panels, the UI updates automatically const grid = Ext.create('Ext.grid.Panel', { store: store, columns: [ { text: 'ID', dataIndex: 'id' }, { text: 'Task', dataIndex: 'name', flex: 1 }, { text: 'Priority', dataIndex: 'priority' } ], renderTo: Ext.getBody() }); // Prepending triggers grid refresh store.insert(0, { id: 0, name: 'Emergency task', priority: 'critical' });
🌐
freeCodeCamp
freecodecamp.org › news › how-to-insert-an-element-into-an-array-in-javascript
Push into an Array in JavaScript – How to Insert an Element into an Array in JS
November 7, 2024 - If there are multiple elements, it specifies where the elements inserted will start. If we want to add to the array, we set the second argument to zero (0), instructing the splice() method not to delete any array elements.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › push
Array.prototype.push() - JavaScript | MDN
Instead, we store the collection on the object itself and use call on Array.prototype.push to trick the method into thinking we are dealing with an array—and it just works, thanks to the way JavaScript allows us to establish the execution context in any way we want. ... const obj = { length: 0, addElem(elem) { // obj.length is automatically incremented // every time an element is added.
Find elsewhere
🌐
W3Schools
w3schools.com › js › js_array_methods.asp
JavaScript Array Methods
The first parameter (0) defines the position where new elements should be added (spliced in). The second parameter (1) defines how many elements should be removed. The rest of the parameters are omitted.
🌐
Sentry
sentry.io › sentry answers › javascript › how to insert an item into an array at a specific index using javascript
How to insert an item into an array at a specific index using JavaScript | Sentry
January 30, 2023 - For example, inserting an item at a specific index in a to-do list. There are various methods to insert an item into an array, broadly divided into those that change the original array and those that don’t. The splice() method is used to change an array by adding, removing, or replacing elements. This method modifies the original array. ... const arr = ["walk the dog", "go shopping", "exercise"]; const index = 2; const value = "go to the pharmacy"; arr.splice(index, 0, value); console.log(arr); // "walk the dog", "go shopping", "go to the pharmacy", "exercise"
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-insert-elements-at-the-beginning-of-js-array
JavaScript - Insert Elements at the Beginning of JS Array - GeeksforGeeks
July 23, 2025 - JavaScript · let a = [10, 20, ... the elements at the beginning of an array, shift the elements of the array to the right by 1 index and insert the new element at the 0th index....
🌐
freeCodeCamp
freecodecamp.org › news › insert-into-javascript-array-at-specific-index
How to Insert into a JavaScript Array at a Specific Index – JS Push
November 7, 2024 - In this code, the splice() method ... of 0. You then add the new element 3 to the array at the start index. The result is the modified array [1, 2, 3, 4, 5]. In this article, you have learned the two major techniques for inserting elements into a JavaScript array at a specific ...
🌐
DigitalOcean
digitalocean.com › community › questions › how-to-insert-an-item-into-an-array-at-a-specific-index-with-javascript
How to insert an item into an array at a specific index with JavaScript? | DigitalOcean
April 9, 2023 - To insert an item at a specific index, you can use the splice() method with the following syntax: ... Here, index is the position where you want to insert the item, 0 indicates that no elements should be removed, and item is the element you ...
🌐
W3Schools
w3schools.com › jsref › jsref_push.asp
JavaScript Array push() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST ... Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
🌐
ReqBin
reqbin.com › code › javascript › vpqnwujy › javascript-array-insert-example
How do I insert elements into an array in JavaScript?
December 16, 2022 - If deleteCount is 0, then the elements are not deleted. If deleteCount is more significant than the number of remaining elements in the array, then all remaining elements of the array will be deleted · element1, ..., elementX (optional): one ...
🌐
Educative
educative.io › answers › how-to-insert-an-element-in-a-specific-index-in-javascript-array
How to insert an element in a specific index in JavaScript Array
There is no method available in ... this. An array starts from index 0, so if we want to add an element as the first element of the array, then the index of the element is 0....
🌐
HostingAdvice
hostingadvice.com › home › how-to
JavaScript "Add to Array" Functions (push vs unshift vs others)
March 25, 2023 - If you want to insert an element (or elements) into a particular point somewhere within the array, besides the beginning or end, then you should most likely be using the splice() method. To use splice() your code should look like this: var list = ["foo", "bar"]; list.splice( 1, 0, "baz"); // at index position 1, remove 0 elements, then add "baz" to that position // element "bar" will now automatically be moved to index position 2 ["foo", "baz", "bar"] // result ·
🌐
CapsCode
capscode.in › blog › different-ways-to-insert-element-in-array-in-javascript
6 Ways To Insert Element In Array
November 6, 2021 - The first parameter you define where in the array you want to insert data. The second parameter you define how many elements you want to delete. We only want to insert elements, so we put 0 here.
🌐
Stack Abuse
stackabuse.com › javascript-how-to-insert-elements-into-a-specific-index-of-an-array
JavaScript: How to Insert Elements into a Specific Index of an Array
September 25, 2023 - The array is 3 in length, and the 2nd element is 3. There is no 3rd element, so we're greeted with undefined. Finally, at that position, we insert the value of 4.