# Map.prototype.with

**URL:** <https://es.discourse.group/t/map-prototype-with/2611>\
**Category:** 💡 Ideas\
**Tags:** proposal\
**Created:** [June 23, 2026, 12:48pm UTC](https://es.discourse.group/t/map-prototype-with/2611 "2026-06-23T12:48:56Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dagur](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/dagur/32/2691_2.png) [@Dagur](https://es.discourse.group/u/Dagur)\
**Post date:** [June 23, 2026, 12:48pm UTC](https://es.discourse.group/t/map-prototype-with/2611/1 "2026-06-23T12:48:56Z")

</div>

I'd like to be able to create a copy of a Map with a single value changed so instead of having to first clone the Map object and then calling Map.prototype.set, I'd like to be able to do this in one call.

`const newMap = mapObject.with("a", 123);`

This is particularly useful when using Maps in react state.

---

<div class="post-metadata">

**Author:** ![Dagur](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/dagur/32/2691_2.png) [@Dagur](https://es.discourse.group/u/Dagur)\
**Post date:** [June 23, 2026, 1:06pm UTC](https://es.discourse.group/t/map-prototype-with/2611/2 "2026-06-23T13:06:50Z")

</div>

I guess this isn't so bad, but it wasn't obvious to me

`const newMap = new Map(mapObject).set("a", 123);`

---

<div class="post-metadata">

**Author:** ![conartist6](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/conartist6/32/515_2.png) [@conartist6](https://es.discourse.group/u/conartist6)\
**Post date:** [June 23, 2026, 3:32pm UTC](https://es.discourse.group/t/map-prototype-with/2611/3 "2026-06-23T15:32:17Z")

</div>

It's not meant to be obvious, because it's a very poor-performing solution.

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [June 23, 2026, 3:34pm UTC](https://es.discourse.group/t/map-prototype-with/2611/4 "2026-06-23T15:34:15Z")

</div>

or even `new Map([...mapObject, ['a', 123]])`

---

<div class="post-metadata">

**Author:** ![aclaymore](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/aclaymore/32/501_2.png) [@aclaymore](https://es.discourse.group/u/aclaymore)\
**Post date:** [June 23, 2026, 4:53pm UTC](https://es.discourse.group/t/map-prototype-with/2611/5 "2026-06-23T16:53:44Z")

</div>

I suspect that would be slower, as it avoids any optimizations engines have for `new Map(map)` (if the iterator hasn't been patched)
