Arrays V/S Objects Performance Analysis
Built-In Data Structures in JavaScript
Through the lens of Big O
What are the easy and fast things that we are doing to an array and objects. Whats the method that might be slower than we expect.. let’s dive into the topic how arrays and objects will perform.
Now that we’ve covered Big O
Let’s spend a couple minutes analyzing the things we do all the time in JS: Working with Arrays, Objects, and built-in methods.
OBJECTIVES
- Understand how Objects and Arrays work, through the lens of Big O
- Explain why adding elements to the beginning of an array is costly.
- Compare and contrast the runtime for arrays and objects, as well as built-in methods
OBJECTS
- Let’s begin by talking about objects, talking about them through the lens of Big O and performance.
- Hopefully, you are familiar with Big O , if not no problem you can learn here
3. Objects are unordered data structures, and everything is stored in Key/Value pairs.

When to use Objects
- Objects work well when you don’t need order.
- When you need fast access / insertion and removal
- When you don’t need any ordering, objects are excellent choice
Big O of Objects
Insertion — O(1)
Removal — O(1)
Searching — O(N)
Access — O(1)
Big O of Object Methods
Object.keys — O(N)
Object.values — O(N)
Object.entries — O(N)
hasOwnProperty — O(1)
ARRAYS
Let’s talk about Arrays , how do they compare to objects. If you are not familiar with Arrays . first go and learn about arrays its a very useful and simple concept.
- Arrays are Ordered lists

When to use Arrays
- When you need order
- When you need fast access / insertion and removal
Big O of Arrays
Insertion — It depends..
Insertion in arrays is depends on how you insert the data to an array, you can insert data from beginning of an array or ending of an array by using shift and push . Once, you did that we have to re-index every element in the array. so, it depends on which way you choose to insert
Removal — It depends..
Removal in arrays is depends on how you remove the value from an array by using pop or unshift. Once, you did that we have to re-index every element in the array. so, it depends on which way you choose to remove.
Searching — O(N)
Access — O(1)
Big O of Array Operations
push — O(1)
pop — O(1)
shift — O(N)
unshift — O(N)
concat — O(N)
slice — O(N)
splice — O(N)
sort — O(N * log N)
forEach/map/filter/reduce/etc. -O(N)
Comparison Objects/Arrays
Objects are super fast when you don’t bother about order. Arrays are great when you avoid using shift and unshift operations . otherwise both are super cool.
Thanks for your time, i am pretty much happier about you , you learnt a cool stuff about objects vs arrays . Any corrections or suggestions or improvements feel free to comment.