When to use which data structures in JavaScript

When to use which data structures in JavaScript

In this article, we will learn about When to use which data structures in JavaScript.

Data Structures in JavaScript

Mainly JavaScript has two data structure Array and Object.

After that two new Data structure introduces in JavaScript which was : Sets and Maps

So, now we have total of four data structures available in JavaScript.

Let's see some cases to indetify which data strctures to use when.



Use when you need ordered list of values and might contain duplicates


Use when you need to manipulate data because there are a lot of useful array methods


Set's looks the same as an array but it also has some scenarios when we consider using sets over the array.

Sets are really not meant to replace arrays but rather to complement them whenever we are dealing with unique values.

Let's see possible cases where we can use sets:


 Use when you need to work with unique values


Use hen high-performance is really important because operations like searching for an item or deleting an item from a set can be up to 10 times faster in sets than in arrays.


Use to remove duplicates from an array


Objects is the traditan key value data strcture before maps introdcues in ES6 but using objects simply as key value stores has a couple of technical disadvantages


Use when you need to include funcitnas or methods


Use when working with JSON(can convert to map)


Maps on other hand are way better suited for simple key vakue stores because they offer better perforamce in fact

Also map keys can have any data typpe and they are also easy to iterate and its easy to compute the size of map


Use when you simply need to map key to values


Use when you need keys that are not strings


Do let me know If you face any difficulties please feel free to comment below we love to help you.

If you have any feedback suggestion then please inform us by commenting.

Don’t forget to share this tutorial with your friends on Facebook and Twitter

Subscribe to our Newsletter

Stay up to date! Get all the latest posts delivered straight to your inbox.

If You Appreciate What We Do Here On TutsCoder, You Should Consider:

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Leave a Comment