<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/use-maps-more-and-objects-less-mzohecjjx" -->

---
title: Use Maps More and Objects Less | daily.dev
description: Objects in JavaScript can be replaced with maps for better performance, easier iteration, and key-value manipulation. Maps are optimized for frequently adding...
canonical: https://daily.dev/posts/use-maps-more-and-objects-less-mzohecjjx
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Use Maps More and Objects Less | daily.dev
og:description: Objects in JavaScript can be replaced with maps for better performance, easier iteration, and key-value manipulation. Maps are optimized for frequently adding...
og:url: https://daily.dev/posts/use-maps-more-and-objects-less-mzohecjjx
og:image: https://api.daily.dev/og/posts/MzOheCjJX.png
og:image:alt: Use Maps More and Objects Less
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Use Maps More and Objects Less

**[builder.io](https://daily.dev/sources/builderio)** · 1 min read · 407 upvotes · 26 comments

## Summary

Objects in JavaScript can be replaced with maps for better performance, easier iteration, and key-value manipulation. Maps are optimized for frequently adding and removing keys, unlike objects. They also solve issues of objects being polluted with built-in keys and provide better iteration methods. Maps can be easily copied, converted to objects, and vice versa. They can also be used for associating metadata with objects. Sets, another similar data structure, provide a better-performing way to create unique lists of elements.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.builder.io/blog/maps>

## Community discussion

Top comments from developers on daily.dev.

**@benthomasknight** · 5 upvotes

> Great article - Maps and Sets are really useful in loops.

**@digeomel** · 4 upvotes

> Very nice article indeed. Unfortunately, you can't just replace all your objects with Maps. Most of us work with libraries and frameworks that work with objects, so you will need to convert between the two all the time. And there is a risk that you might forget you're dealing with either, and there are some gotchas when treating Maps like objects, instead of using the dedicated Map functions mentioned in the article.

**@tuzebra** · 2 upvotes

> Hi, thanks for very well detailed article.
>
> At the WeakSet example
> ```
> // No memory leaks here, captain 🫡
> const checkedTodos = new Set([todo1, todo2, todo3])
> ```
> I thought it should be "new WeakSet(..."
>
>
> Regarding the JSON.stringify section, there is another alternative if you do not want to pass in the "replacer" every time you call JSON.stringify.
>
> ```
> class MySet extends Set{
>     toJSON(){
>         return [...this]
>     }
> }
> ```
>
> So by using `MySet` instead of `Set`,
> ```
> const a = new MySet([1,2,3,4,5]);
> JSON.stringify(a);
> // '[1,2,3,4,5]'
> ```
>
> Unfortunately, there is no similar option...

**@heyvaldemar** · 2 upvotes

> I use Google Maps to find objects. Is that it?

**@bonaogeto** · 2 upvotes

> Well detailed.
>
> Thanks for sharing!

## Similar posts on daily.dev

- [Don’t just attend KubeCon \+ CloudNativeCon, Merge Forward your experience\!](https://daily.dev/posts/don-t-just-attend-kubecon-cloudnativecon-merge-forward-your-experience--l0rpp73x8) · CNCF · 1 upvotes · 0 comments
- [Announcing H2 2026 KCDs](https://daily.dev/posts/announcing-h2-2026-kcds-m96goajm1) · CNCF · 1 upvotes · 0 comments
- [Two months of Open Community Groups](https://daily.dev/posts/two-months-of-open-community-groups-asf52zhbs) · CNCF · 0 upvotes · 0 comments
- [CNCF Unveils Schedule for KubeCon \+ CloudNativeCon Europe 2026](https://daily.dev/posts/cncf-unveils-schedule-for-kubecon-cloudnativecon-europe-2026-ikhcoa5cb) · CNCF · 2 upvotes · 0 comments
- [CNCF Debuts KubeCon \+ CloudNativeCon Japan 2026 Schedule](https://daily.dev/posts/cncf-debuts-kubecon-cloudnativecon-japan-2026-schedule-xp5pyudub) · CNCF · 1 upvotes · 0 comments

---

Tags: [#javascript](https://daily.dev/tags/javascript), [#performance](https://daily.dev/tags/performance)

[View this post on daily.dev](https://daily.dev/posts/use-maps-more-and-objects-less-mzohecjjx)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Use Maps More and Objects Less","url":"https://daily.dev/posts/use-maps-more-and-objects-less-mzohecjjx","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/use-maps-more-and-objects-less-mzohecjjx"},"datePublished":"2023-02-08T02:51:06.389Z","dateModified":"2024-04-04T11:24:14.756Z","description":"Objects in JavaScript can be replaced with maps for better performance, easier iteration, and key-value manipulation. Maps are optimized for frequently adding...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/fa75e53dbbcaf98d7bfacf765e895eb6?_a=AQAEufR","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/fa75e53dbbcaf98d7bfacf765e895eb6?_a=AQAEufR","isAccessibleForFree":true,"articleSection":"builder.io","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"builder.io","logo":"https://media.daily.dev/image/upload/s--jap1dv3o--/f_auto/v1721914613/squads/builderio","url":"https://daily.dev/squads/builderio"},"commentCount":26,"discussionUrl":"https://daily.dev/posts/use-maps-more-and-objects-less-mzohecjjx","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":407},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":26}],"keywords":"javascript,performance","timeRequired":"PT1M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"builder.io","item":"https://daily.dev/squads/builderio"},{"@type":"ListItem","position":3,"name":"Use Maps More and Objects Less"}]}
{"@context":"https://schema.org","@type":"WebPage","@id":"https://daily.dev/posts/use-maps-more-and-objects-less-mzohecjjx","comment":[{"@type":"Comment","text":"Great article - Maps and Sets are really useful in loops.","datePublished":"2023-02-08T02:59:46.448Z","url":"https://daily.dev/posts/MzOheCjJX#c-ZfCmfkX8l","author":{"@type":"Person","name":"Ben Knight","url":"https://daily.dev/benthomasknight","image":"https://avatars.githubusercontent.com/u/20388953?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":5}},{"@type":"Comment","text":"Very nice article indeed. Unfortunately, you can’t just replace all your objects with Maps. Most of us work with libraries and frameworks that work with objects, so you will need to convert between the two all the time. And there is a risk that you might forget you’re dealing with either, and there are some gotchas when treating Maps like objects, instead of using the dedicated Map functions mentioned in the article.","datePublished":"2023-02-08T13:30:23.449Z","url":"https://daily.dev/posts/MzOheCjJX#c-n7206DNZw","author":{"@type":"Person","name":"Dimitris","url":"https://daily.dev/digeomel","image":"https://avatars3.githubusercontent.com/u/3295889?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":4}},{"@type":"Comment","text":"Hi, thanks for very well detailed article.\nAt the WeakSet example\n// No memory leaks here, captain 🫡\nconst checkedTodos = new Set([todo1, todo2, todo3])\n\nI thought it should be “new WeakSet(…”\nRegarding the JSON.stringify section, there is another alternative if you do not want to pass in the “replacer” every time you call JSON.stringify.\nclass MySet extends Set{\n    toJSON(){\n        return [...this]\n    }\n}\n\nSo by using MySet instead of Set,\nconst a = new MySet([1,2,3,4,5]);\nJSON.stringify(a);\n// '[1,2,3,4,5]'\n\nUnfortunately, there is no similar option available for JSON.parse.","datePublished":"2023-02-09T16:28:41.359Z","url":"https://daily.dev/posts/MzOheCjJX#c-dZXO6WuqL","author":{"@type":"Person","name":"Huy Phan","url":"https://daily.dev/tuzebra","image":"https://lh3.googleusercontent.com/a-/AOh14GggUOiCRUwA9lkhRRZ2-_bFFz1bKmCHyuJIEunTFw=s100"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2}},{"@type":"Comment","text":"I use Google Maps to find objects. Is that it?","datePublished":"2023-02-08T22:20:11.081Z","url":"https://daily.dev/posts/MzOheCjJX#c-ZHX_xMMEr","author":{"@type":"Person","name":"Valdemar","url":"https://daily.dev/heyvaldemar","image":"https://media.daily.dev/image/upload/s--hNY2yBbX--/f_auto/v1768758611/avatars/avatar_ft0iS8AcGd90jdHVINKGp?_a=BAMAMiiu0"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2}},{"@type":"Comment","text":"Well detailed.\nThanks for sharing!","datePublished":"2023-02-08T05:29:02.689Z","url":"https://daily.dev/posts/MzOheCjJX#c-AW1rAIVhH","author":{"@type":"Person","name":"Bonaventure Ogeto","url":"https://daily.dev/bonaogeto","image":"https://avatars.githubusercontent.com/u/39027629?v=4"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":2}}]}
```

