# Update map in loop

**URL:** <https://forum.elixirforum.com/t/update-map-in-loop/47172>\
**Category:** Questions\
**Tags:** comprehensions, loop, map\
**Created:** [April 12, 2022, 1:18pm UTC](https://forum.elixirforum.com/t/update-map-in-loop/47172 "2022-04-12T13:18:41Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![ConstantBall](https://forum.elixirforum.com/letter_avatar_proxy/v4/letter/c/e8c25b/32.png) [@ConstantBall](https://forum.elixirforum.com/u/ConstantBall)\
**Post date:** [April 13, 2022, 11:07pm UTC](https://forum.elixirforum.com/t/update-map-in-loop/47172/5 "2022-04-13T23:07:05Z")

</div>

This will give a value of `nil` to `"associated_products"` if the `product_id` doesn’t exist in the `associated_products` map. Is that the behaviour you want? Are you looking to set another default value if that’s the case? Or do you only want to insert `"associated_products"` into `order["products"][product_id]` if `associated_products[product_id]` exists?

---

_[View the full topic](https://forum.elixirforum.com/t/update-map-in-loop/47172)._
