Difference between Map and set
Map | Set |
---|---|
It is a collection of key-value | It is a collection of unique elements |
Map is two-dimensional | The set is one dimensional |
Values are accessed using keys | In-built methods are used to access values |
Set vs Map in JavaScript
In JavaScript, Set and Map are two types of objects that are used for storing data in an ordered manner. Both these data structures are used to store distinct types of data inside the same object. In Maps, the data is stored as a key-value pair whereas in Set data is a single collection of values that are unique.
Let’s learn about the uses of these two data structures.