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
🌐
Medium
medium.com › @inbasekaran18 › understanding-time-complexity-of-array-methods-in-javascript-cc7bb30b3e9d
Understanding Time Complexity of Array Methods in JavaScript | by Inbasekaran | Medium
May 29, 2024 - In this article, we’ll take a detailed look at the time complexities of common array methods and how they impact performance.
🌐
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 - For best-case big-omega is used (e.g., Ω(n)) and for average-case big-theta is used (e.g., Θ(n)). Notice the internal ligature of the big-theta vs that of a big O as it may be easy to mistake one for the other. ... What reference did you lean on to find their time complexity? If their complexities are assumed or inferred, I'm not sure the assumptions hold, since each engine implements JS arrays differently.
Discussions

JavaScript runtime complexity of Array functions - Stack Overflow
Is the runtime complexity defined by the JS standard on common Array functions like push, pop, shift, slice or splice? Esp. I'm interested in removing and inserting entries at random positions. If ... More on stackoverflow.com
🌐 stackoverflow.com
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
Big O of JavaScript arrays - Stack Overflow
Arrays in JavaScript are very easy to modify by adding and removing items. It somewhat masks the fact that most languages arrays are fixed-size, and require complex operations to resize. It seems t... More on stackoverflow.com
🌐 stackoverflow.com
Time complexity of Javascript Array.find() in modern browsers - Stack Overflow
1 Javascript: Running time of search through Object? 97 JavaScript runtime complexity of Array functions 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 most common ways I can think of to add an element to an existing array are with the Array.push() method which adds an element at the end of an array and the Array.unshift() method which adds an element to the beginning of an array. You may think they work the same way and so should have the same Time Complexity.
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.

🌐
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 - Linear Time Complexity O(n) means we will need to make the calculation constant number of times for each element (when n is the number of elements) so as the input grows, the runtime grows.
Top answer
1 of 2
135

NOTE: While this answer was correct in 2012, engines use very different internal representations for both objects and arrays today. This answer may or may not be true.

In contrast to most languages, which implement arrays with, well, arrays, in Javascript Arrays are objects, and values are stored in a hashtable, just like regular object values. As such:

  • Access - O(1)
  • Appending - Amortized O(1) (sometimes resizing the hashtable is required; usually only insertion is required)
  • Prepending - O(n) via unshift, since it requires reassigning all the indexes
  • Insertion - Amortized O(1) if the value does not exist. O(n) if you want to shift existing values (Eg, using splice).
  • Deletion - Amortized O(1) to remove a value, O(n) if you want to reassign indices via splice.
  • Swapping - O(1)

In general, setting or unsetting any key in a dict is amortized O(1), and the same goes for arrays, regardless of what the index is. Any operation that requires renumbering existing values is O(n) simply because you have to update all the affected values.

2 of 2
5

guarantee

There is no specified time complexity guarantee for any array operation. How arrays perform depends on the underlying datastructure the engine chooses. Engines might also have different representations, and switch between them depending on certain heuristics. The initial array size might or might not be such an heuristic.

reality

For example, V8 uses (as of today) both hashtables and array lists to represent arrays. It also has various different representations for objects, so arrays and objects cannot be compared. Therefore array access is always better than O(n), and might even be as fast as a C++ array access. Appending is O(1), unless you reach the size of the datastructure and it has to be scaled (which is O(n)). Prepending is worse. Deletion can be even worse if you do something like delete array[index] (don't!), as that might force the engine to change its representation.

advice

Use arrays for numeric datastructures. That's what they are meant for. That's what engines will optimize them for. Avoid sparse arrays (or if you have to, expect worse performance). Avoid arrays with mixed datatypes (as that makes internal representations more complex).

If you really want to optimize for a certain engine (and version), check its sourcecode for the absolute answer.

🌐
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 - But, like the previous sorts, this also requires comparing each item to the rest of the collection, therefore, it has an average to worst case complexity of O(n²). Like the bubble sort, if there is only one item left to sort, it only requires ...
Find elsewhere
🌐
GitHub
gist.github.com › thm-design › af870d56b608ae96acf052380a986e6a
Time & space complexity in javascript · GitHub
However, for most common use cases, the complexities of JavaScript iteration methods are O(n) for time and O(1) for space. The time and space complexity of rendering React components from an array depends on several factors, such as the size ...
🌐
Mblogs
mbloging.com › home › dsa › understanding time complexity of javascript array operations
Understanding Time Complexity of JavaScript Array Operations | Mbloging
April 15, 2025 - 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 ...
Top answer
1 of 1
33

V8 developer here. The time complexity of Array.prototype.find is O(n) (with n being the array's length), and it's fair to assume that it will remain that way.

Generally speaking, it's often impossible for engines to improve the complexity class of an operation. In case of Array.prototype.find, the predicate function you pass might well care how often it gets called:

[1, 2, 3].find((value, index, object) => {
  console.log(`Checking ${value}...`);  // Or any other side effect.
  return value === 42;
});

In such a case, the engine has no choice but to iterate over the entire array in exactly the right order, because anything else would observably break your program's behavior.

In theory, since JS engines can do dynamic optimizations, they could inspect the predicate function, and if it has no side effects, they could use it to build up some sort of index/cache. Aside from the difficulty of building such a system that works for arbitrary predicates, this technique even when it does work would only speed up repeated searches of the same array with the same function, at the cost of wasting time and memory if this exact same scenario will not occur again. It seems unlikely that an engine can ever make this prediction with sufficient confidence to justify investing this time and memory.

As a rule of thumb: when operating on large data sets, choosing efficient algorithms and data structures is worth it. Typically far more worth it than the micro-optimizations we're seeing so much in SO questions :-)

A highly optimized/optimizing engine may be able to make your O(n) code somewhere between 10% and 10x as fast as it would otherwise be. By switching to an O(log n) or O(1) solution on your end, you can speed it up by orders of magnitude. That's often accomplished by doing something that engines can't possibly do. For example, you can keep your array sorted and then use binary search over it -- that's something an engine can't do for you automatically because obviously it's not allowed to reorder your array's contents without your approval. And as @myf already points out in a comment: if you want to access things by a unique key, then using a Map will probably work better than using an Array.

That said, simple solutions tend to scale better than we intuitively assume; the standard warning against premature optimizations applies here just as everywhere else. Linearly searching through arrays is often just fine, you don't need a (hash) map just because you have more than three items in it. When in doubt, profile your app to find out where the performance bottlenecks are.

🌐
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 - In Big-O notation, we commonly see: O(1) (Constant Time): Performance remains the same, no matter the array size. O(n) (Linear Time): Performance grows directly with the number of elements.
🌐
JavaScript in Plain English
javascript.plainenglish.io › under-the-hood-worst-case-complexities-workings-of-popular-js-array-methods-739d5fef314a
Worst Case Complexities & Workings of Popular JS Array Methods | JavaScript in Plain English
August 9, 2022 - In this article, we will delve into the behind-the-scenes working and the efficiency of these methods. There is no specified time complexity guarantee for any array operation. How arrays perform depends on the underlying data structure the engine chooses. Engines might also have different ...
🌐
Medium
tharinducs.medium.com › time-complexity-of-objects-and-arrays-js-algo-02-5cd8ead23b91
Time Complexity of Objects and Arrays — JS Algo 02 | by Tharindu Senadheera | Medium
February 18, 2023 - Time Complexity of Objects and Arrays — JS Algo 02 Let’s have a look at the Big O Time Complexity of Objects and Array Methods. 1. Objects — Big O const wizard = { firstName : 'Harry' …
🌐
Reddit
reddit.com › r/learnjavascript › what is the time complexity of array de-structuring?
r/learnjavascript on Reddit: What is the time complexity of array de-structuring?
December 15, 2022 - ... You are implicitly specifying the index, starting from zero and following the order of each new variable you define (a, b and so on) so this should be O(1) or constant time. Source.
🌐
Medium
medium.com › @chinweregina › object-array-time-and-space-complexity-in-javascript-00792792dfc5
Object/Array Time and Space Complexity in JavaScript | by Chinwe Regina | Medium
October 16, 2023 - The following Object methods also have linear time complexity. ... · Insert / Remove at the end — O(1): 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) because they only impact the array’s last element.
🌐
JavaScript in Plain English
javascript.plainenglish.io › understanding-time-and-space-complexity-of-common-javascript-built-in-methods-39a3285a6409
Understanding Time and Space Complexity of Common JavaScript Built-in Methods | by Kyle Le | JavaScript in Plain English
April 14, 2023 - Here are the time and space complexities of some common JavaScript built-in methods: Array.prototype.concat(): O(n) time complexity and O(n) space complexity. This method creates a new array that includes elements from the original array(s).
🌐
Medium
medium.com › @mohammad.rostami13 › time-and-space-complexity-javascript-array-methods-a1dbe7dd23e3
Time and Space Complexity Javascript Array methods | by Mohammad Rostami | Medium
March 31, 2023 - I think that it is very important to understand the time and space complexity for the common Array methods that we used to create our algorithms and in this way we can calculte the complexity of the whole structure. JavaScript Array methods are a set of built-in functions that can be used to ...