Menu

Post image 1
Post image 2
1 / 2
0

Map and Set in JavaScript

DEV Community·Pratham·23 days ago
#iur7K8bG
#when#part#creating#visual#const#fullscreen
Reading 0:00
15s threshold

Two data structures that solve problems objects and arrays can't — and when you should reach for them. For a while, I thought JavaScript only had two ways to store data: objects (key-value pairs) and arrays (ordered lists). They handle most situations, so I never questioned whether there was something better. Then I ran into two problems that made me realize their limitations: Problem 1: I needed an object where the keys were other objects , not just strings. Regular objects can't do that — every key gets converted to a string. Problem 2: I needed an array with no duplicates. I kept adding values and then manually checking "wait, is this already in there?" before each insertion. Both problems have clean solutions: Map and Set . They were introduced in ES6 (2015), and once you understand what they do, you'll wonder why you didn't learn them sooner. Let me walk you through both. What Is a Map? A Map is a collection of key-value pairs — similar to an object — but with some important upgrades.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More