As I known.

The shift command is come from the binary bit shift [1]. for Example.

    001100
0 < 011000 // when you shift left
|
Yay!

I think it is quite simple it is just like you push it from behind. So this makes sense for me.

The unshift is the opposite way of shift.

    001100
1 > 001100 // they called it unshift
    1001100
    |
    Yay!

So that's it, Hope this helps!

[1] http://en.wikipedia.org/wiki/Bitwise_operation#Bit_shifts

Answer from Chokchai on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › unshift
Array.prototype.unshift() - JavaScript | MDN
The unshift() method reads the length property of this. It shifts all indices in the range 0 to length - 1 right by the number of arguments (incrementing their values by this number). Then, it sets each index starting at 0 with the arguments passed to unshift().
🌐
W3Schools
w3schools.com › jsref › jsref_unshift.asp
JavaScript Array unshift() Method
❮ Previous JavaScript Array Reference ... fruits.unshift("Lemon","Pineapple"); Try it Yourself » · The unshift() method adds new elements to the beginning of an array....
🌐
CodingNomads
codingnomads.com › javascript-array-unshift-shift-pop-push
JavaScript Array Essentials: Using pop, push, shift, and unshift
The .unshift() method is then called with "purple" as an argument, which adds "purple" to the beginning of the array. Next, the shift() method is used, which removes the first element ("purple") from the array, reverting it back to its original form...
🌐
Reddit
reddit.com › r/learnjavascript › who thought "unshift()" was a good name? why?
r/learnjavascript on Reddit: Who thought "unshift()" was a good name? Why?
December 20, 2023 -

EDIT: This is just venting, not confusion on how the word is technically used by JS :D

OK, this is why I keep starting and stopping learning JS- reserved words with extremely unrelated English meanings. "Unshift" means a previous shift occurred. That's the only meaning for it in English. But JS decided to use it as a prepend array method. Argh!!

That is all...

🌐
Career Karma
careerkarma.com › blog › javascript › javascript shift and javascript unshift: a complete guide
JavaScript Shift and JavaScript Unshift: A Complete Guide
December 1, 2023 - JavaScript shift() removes an element at a specified position and shifts the remaining elements up. The JavaScript unshift() function does the opposite.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-array-unshift-method
JavaScript Array unshift() Method - GeeksforGeeks
July 15, 2024 - JavaScript Array unshift() Method is used to add one or more elements to the beginning of the given array.
Find elsewhere
🌐
Medium
medium.com › an-idea › javascript-arrays-push-pop-shift-unshift-adc8fb815fc0
JavaScript Arrays: push(), pop(), shift() & unshift() | by Amanda M Johnson | An Idea (by Ingenious Piece) | Medium
October 10, 2021 - JavaScript Arrays: push(), pop(), shift() & unshift() When working with arrays, it is important to understand the different types of methods and how they transform your data. push(), pop(), shift() …
🌐
Programiz
programiz.com › javascript › library › array › unshift
JavaScript Array unshift()
var languages = ["JavaScript", "Python", "Java", "Lua"]; var count = languages.unshift("C++"); console.log(languages); // [ 'C++', 'JavaScript', 'Python', 'Java', 'Lua' ] console.log(count); // 5 var priceList = [12, 21, 35];
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › shift
Array.prototype.shift() - JavaScript | MDN
const arrayLike = { length: 3, unrelated: "foo", 2: 4, }; console.log(Array.prototype.shift.call(arrayLike)); // undefined, because it is an empty slot console.log(arrayLike); // { '1': 4, length: 2, unrelated: 'foo' } const plainObj = {}; // There's no length property, so the length is 0 Array.prototype.shift.call(plainObj); console.log(plainObj); // { length: 0 } Indexed collections guide · Array · Array.prototype.push() Array.prototype.pop() Array.prototype.unshift() Array.prototype.concat() Array.prototype.splice() Was this page helpful to you?
🌐
Medium
developerchandan.medium.com › mastering-array-manipulation-in-javascript-exploring-pop-push-shift-unshift-splice-and-slice-c0ebaf3b004c
“Mastering Array Manipulation in JavaScript: Exploring pop, push, shift, unshift, splice, and slice Methods” | by Chandan Kumar | Medium
June 2, 2023 - let fruits = ['apple', 'banana', ... unshift():-The unshift() method, on the other hand, adds one or more elements to the beginning of an array and returns the new length of the array....
🌐
Meticulous
meticulous.ai › blog › javascript-unshift-complete-guide
JavaScript Unshift | In-Depth Guide & Tutorial
Unshift is a method for adding elements to the beginning of an array or an object resembling an array. It's one of the most commonly used JavaScript methods when dealing with arrays and has the signature of unshift(element1, element2... elementN).
🌐
Linux Hint
linuxhint.com › javascript-array-shift-and-unshift-method
JavaScript Array Shift and Unshift Method
Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
Medium
medium.com › @andrewasmit › array-method-madness-a-review-of-push-pop-shift-unshift-slice-splice-d51c84ed778b
Array Method Madness: a review of .push() .pop() .shift() .unshift() .slice() & .splice() | by Andrew Smit | Medium
October 26, 2022 - Just like with the .push() method, if I take the code where I invoke .unshift() and save that to a variable, the variable’s value will be a number that shows the length of the modified array.
Top answer
1 of 9
70

push() is faster.

js>function foo() {a=[]; start = new Date; for (var i=0;i<100000;i++) a.unshift(1); return((new Date)-start)}
js>foo()
2190
js>function bar() {a=[]; start = new Date; for (var i=0;i<100000;i++) a.push(1); return((new Date)-start)}
js>bar()
10

function foo() {a=[]; start = new Date; for (var i=0;i<100000;i++) a.unshift(1); return((new Date)-start)}
console.log(foo())

function bar() {a=[]; start = new Date; for (var i=0;i<100000;i++) a.push(1); return((new Date)-start)}
console.log(bar());


Update

The above does not take into consideration the order of the arrays. If you want to compare them properly, you must reverse the pushed array. However, push then reverse is still faster by ~10ms for me on chrome with this snippet:

var a=[]; 
var start = new Date; 
for (var i=0;i<100000;i++) {
  a.unshift(1);
}
var end = (new Date)-start;
console.log(`Unshift time: ${end}`);

var a=[];
var start = new Date;
for (var i=0;i<100000;i++) {
  a.push(1);
}

a.reverse();
var end = (new Date)-start;
console.log(`Push and reverse time: ${end}`);

2 of 9
29

The JavaScript language spec does not mandate the time complexity of these functions, as far as I know.

It is certainly possible to implement an array-like data structure (O(1) random access) with O(1) push and unshift operations. The C++ std::deque is an example. A Javascript implementation that used C++ deques to represent Javascript arrays internally would therefore have O(1) push and unshift operations.

But if you need to guarantee such time bounds, you will have to roll your own, like this:

http://code.stephenmorley.org/javascript/queues/

🌐
Bennadel
bennadel.com › blog › 1796-javascript-array-methods-unshift-shift-push-and-pop.htm
Javascript Array Methods: Unshift(), Shift(), Push(), And Pop()
April 21, 2020 - This question probably doesn't have any real world application, but I have a JavaScript exercise that asks me to .unshift a variable to the front of my array then simultaneously remove it with the .shift method.
🌐
DEV Community
dev.to › tochi_ › javascript-array-methods-under-the-hood-unshift-and-shift-explained-3gd
JavaScript Array Methods Under the Hood: Unshift and Shift Explained - DEV Community
July 31, 2025 - If you have an array and you want to add something to the front, i.e index 0, JavaScript has to move every other item one step forward to make space. Imagine shifting people in a line forward to make room for one more at the start. That takes time. Let’s look at what unshift() does under the hood.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › what-is-the-difference-between-unshift-and-push-method-in-javascript
What is the difference between unshift() and Push() method in JavaScript? - GeeksforGeeks
July 23, 2025 - JavaScript Unshift() method is very much similar to the push() method but the difference is that the unshift() method adds the elements at the very beginning of the array whereas the push() method adds at the end of the array.