The ECMA specification does not specify a bounding complexity, however, you can derive one from the specification's algorithms.

push is O(1), however, in practice it will encounter an O(N) copy costs at engine defined boundaries as the slot array needs to be reallocated. These boundaries are typically logarithmic.

pop is O(1) with a similar caveat to push but the O(N) copy is rarely encountered as it is often folded into garbage collection (e.g. a copying collector could only copy the used part of an array).

shift is at worst O(N) however it can, in specially cases, be implemented as O(1) at the cost of slowing down indexing so your mileage may vary.

slice is O(N) where N is end - start. Not a tremendous amount of optimization opportunity here without significantly slowing down writes to both arrays.

splice is, worst case, O(N). There are array storage techniques that divide N by a constant but they significantly slow down indexing. If an engine uses such techniques you might notice unusually slow operations as it switches between storage techniques triggered by access pattern changes.

One you didn't mention, is sort. It is, in the average case, O(N log N). However, depending on the algorithm chosen by the engine, you could get O(N^2) in some cases. For example, if the engine uses QuickSort (even with an late out to InsertionSort), it has well-known N^2 cases. This could be a source of DoS for your application. If this is a concern either limit the size of the arrays you sort (maybe merging the sub-arrays) or bail-out to HeapSort.

Answer from chuckj on Stack Overflow
Top answer
1 of 3
185

The ECMA specification does not specify a bounding complexity, however, you can derive one from the specification's algorithms.

push is O(1), however, in practice it will encounter an O(N) copy costs at engine defined boundaries as the slot array needs to be reallocated. These boundaries are typically logarithmic.

pop is O(1) with a similar caveat to push but the O(N) copy is rarely encountered as it is often folded into garbage collection (e.g. a copying collector could only copy the used part of an array).

shift is at worst O(N) however it can, in specially cases, be implemented as O(1) at the cost of slowing down indexing so your mileage may vary.

slice is O(N) where N is end - start. Not a tremendous amount of optimization opportunity here without significantly slowing down writes to both arrays.

splice is, worst case, O(N). There are array storage techniques that divide N by a constant but they significantly slow down indexing. If an engine uses such techniques you might notice unusually slow operations as it switches between storage techniques triggered by access pattern changes.

One you didn't mention, is sort. It is, in the average case, O(N log N). However, depending on the algorithm chosen by the engine, you could get O(N^2) in some cases. For example, if the engine uses QuickSort (even with an late out to InsertionSort), it has well-known N^2 cases. This could be a source of DoS for your application. If this is a concern either limit the size of the arrays you sort (maybe merging the sub-arrays) or bail-out to HeapSort.

2 of 3
17

in very simple words

push -> O(1)

pop -> O(1)

shift -> O(N)

slice -> O(N)

splice -> O(N)

Here is a complete explanation about time complexity of Arrays in JavaScript.

๐ŸŒ
DEV Community
dev.to โ€บ lukocastillo โ€บ time-complexity-big-0-for-javascript-array-methods-and-examples-mlg
Time complexity Big 0 for Javascript Array methods and examples. - DEV Community
June 3, 2020 - That is the reason why I wanted to write this post, to understand the time complexity for the most used JS Array methods. So, let's start with a quick definition of the method, his time complexity, and a small example. 1. push() - 0(1) Add ...
Discussions

arrays - Time complexity of unshift() vs. push() in Javascript - Stack Overflow
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. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Is there a resource to find the time complexity for common methods
Blog Array iteration methods are going to be O(n) if they iterate through 1x, e.g.: forEach map reduce entries find some every Or if they convert the entire array or a subset of the array to a new form slice splice spread/rest Or O(n) if they require that the entire array be recalculated shift unshift Or O(1) if they directly access a property arr[index] Or O(1) if they modify the last element in the array push pop Or O(nlogn) if they have to make multiple passes through the array, but each pass decreases in size sort Once you understand Space/Time complexities and have a rough idea of what is happening under the hood, it's pretty easy to just guess. More on reddit.com
๐ŸŒ r/learnjavascript
8
1
November 1, 2022
How do you find time complexity when using Javascript array methods
I believe this one is effectively quadratic. Or to be specific, O(mn), where m = arr.length and n = arr2.length. Filter is linear if its callback is constant. But in this case the callback is also linear. if the arrays increase in length the time would also increase. You can only deduce that it's not constant from this. It doesn't tell you whether it's linear, logarithmic, exponential, quadratic, etc. If arr2 is sorted, you could improve the runtime by using a binary search on it. If both arrays are sorted, I'm pretty sure you could make this effectively linear, though I'm not sure how you'd write that functionally. More on reddit.com
๐ŸŒ r/webdev
8
1
July 22, 2023
javascript - Time complexity of Array.from - Stack Overflow
The time complexity depends on the internal implementation so it could be O(n log n) if internally it uses something like Array.prototype.push to add elements to the returned array. That would be a stupid way to implement that, but until I see otherwise I am assuming the worst. More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Medium
medium.com โ€บ @ashfaqueahsan61 โ€บ time-complexities-of-common-array-operations-in-javascript-c11a6a65a168
Time Complexities Of Common Array Operations In JavaScript | by Ashfaque Ahsan | Medium
September 4, 2019 - The Array.push() has a Constant Time Complexity and so is O(1). All it does is add an element and give it an index thatโ€™s 1 greater than the index of the last element in the array.
๐ŸŒ
DEV Community
dev.to โ€บ technoph1le โ€บ the-javascript-arraypush-method-explained-5d4m
The JavaScript `Array.push()` method explained - DEV Community
November 24, 2022 - Because when a new element is added to the beginning of an array, all the other elements in the array must be shifted over by one index. const array1 = ["a", "b", "c"]; const array2 = ["d", "e", "f"]; array1.push(...array2); console.log(array1); ...
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/

๐ŸŒ
Medium
omken.medium.com โ€บ javascripts-push-pop-shift-and-unshift-array-methods-with-respect-to-big-o-notation-e129ac5464
JavaScriptโ€™s Push, Pop, Shift, and Unshift Array Methods With Big O Notation. | by Omkesh B. Kendre | Medium
November 28, 2022 - In other words, it determines an algorithmโ€™s worst-case time complexity. The maximum runtime of an algorithm is expressed using the Big O Notation in data structures. One or more elements are added to the end of an array using the push() method, which also returns the arrayโ€™s new length This technique modifies the arrayโ€™s length.
๐ŸŒ
Witch
witch.work โ€บ en โ€บ posts โ€บ javascript-array-insert-time-complexity
Exploring JavaScript - Time Complexity of Array Insertion Methods
February 22, 2024 - By ignoring error checking and ... Therefore, the time complexity can be considered O(number of arguments), and if the number of arguments is constant, it is O(1)....
๐ŸŒ
Hey
world.hey.com โ€บ mgmarlow โ€บ time-complexity-of-array-push-d950f9dc
Time complexity of Array.push
April 3, 2021 - In terms of time complexity, push is O(1) if the array has room to fit the new element and O(n) if it needs to allocate more space. Since Big O is concerned with worst-case performance, it follows that push is O(n).
Find elsewhere
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ javascript array push() method
JavaScript Array push() Method - Scaler Topics
June 8, 2023 - Consider performance implications ... length of the new array as a return value. Time complexity of using the push method is constant O(1) space complexity is linear O(N)....
๐ŸŒ
Mblogs
mbloging.com โ€บ home โ€บ dsa โ€บ understanding time complexity of javascript array operations
Understanding Time Complexity of JavaScript Array Operations | Mbloging
April 15, 2025 - Let's delve deeper into the time complexities associated with various array operations in JavaScript. Accessing elements in an array by index is considered a constant time operation (O(1)). Regardless of the array's size, accessing an element at a specific index takes the same amount of time because arrays provide direct access to memory locations using index values. Appending elements at the end of an array using the push method or removing elements from the end using the pop method operates in constant time (O(1)).
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ the-complexity-of-simple-algorithms-and-data-structures-in-javascript-11e25b29de1e
The complexity of simple algorithms and data structures in JS
March 18, 2019 - Because it takes a single step to access an item of an array via its index, or add/remove an item at the end of an array, the complexity for accessing, pushing or popping a value in an array is O(1).
๐ŸŒ
CodingNomads
codingnomads.com โ€บ javascript-array-unshift-shift-pop-push
JavaScript Array Essentials: Using pop, push, shift, and unshift
This is because each element in the array must be moved to a new position when an item is added to or removed from the beginning of the array. On the other hand, .pop() and .push() have a time complexity of O(1), which means their execution ...
๐ŸŒ
Medium
medium.com โ€บ @yaelfisher โ€บ learning-about-time-complexity-with-javascript-arrays-methods-b8c2a8ee2101
Learning about Time Complexity with Javascript Array Methods | by Yael Fisher | Medium
February 26, 2022 - Its position is updated to zoo[4] and then all the other animalsโ€™ position gets updated as long as the array is, so the complexity will be O(n). The purpose of this article was to familiarize ourselves with under-the-hood Javascript array methods regarding time complexity.
๐ŸŒ
AlgoCademy
algocademy.com โ€บ link
Time Complexity Practice 1 in JavaScript | AlgoCademy
This function creates a new array populated with the results of calling a provided function on every element in the calling array. The time complexity is O(n) because it iterates over each element of the array.
๐ŸŒ
Quora
quora.com โ€บ What-is-the-time-complexity-of-the-push-and-pop-operation-of-an-array-based-stack
What is the time complexity of the push and pop operation of an array-based stack? - Quora
Answer (1 of 7): Push : Every time a new element is added at the end of array. So, irrespective of number of elements already in the array, this operation will always take same time. So it will be O(1). Pop : Every time first element of array is removed, all remaining n-1 elements are moved up. ...
๐ŸŒ
Medium
medium.com โ€บ @grajdeep2000 โ€บ understanding-the-javascript-array-methods-and-their-time-complexity-0c72b068e3da
Understanding the JavaScript Array Methods and their Time Complexity | by Grajdeep | Medium
March 4, 2025 - Use .sort() wisely, as sorting is O(n log n). Consider data structures like Set for efficient lookups. By understanding time complexity, youโ€™ll write faster, scalable, and more efficient JavaScript code!