DEV Community

Maps in JavaScript

Atta on June 19, 2019

This post was originally published on attacomsian.com/blog. Maps are a new data structure in JavaScript that allows you to create collections o...
Collapse
 
georgecoldham profile image
George

This is a great overview! I was expecting it to be the other map as that seems to be what people focus on and use more. But I am pleasantly surprised that you are highlighting less used but very useful functionality.

Why people dont use these more is a mystery to me. I often see people using Objects or even JSON without ever stopping to think about Map

Collapse
 
attacomsian profile image
Atta

May be because Maps are relatively new (introduced in ES6) whereas Objects are around since JavaScript version 1 and supported by all browsers.

Collapse
 
laurieontech profile image
Laurie

Same though!

Collapse
 
emnudge profile image
EmNudge

You wrote

Calling add() more than once with the same key won't add multiple key-value pairs.

I believe you may have meant set()

Collapse
 
attacomsian profile image
Atta

Yeah, it should be set() method for maps :) I updated the post.

Collapse
 
calag4n profile image
calag4n

Wow, I didn't know that, thanks !
I don't see use cases for now but it seems pretty cool .

Collapse
 
dharmelolar profile image
Dharmelolar Ezekiel

Thank you so much for this post. I've been stucked on map for awhile now and i have been using references online but this is the only one i've found useful so far.

Collapse
 
attacomsian profile image
Atta

Thank you! I'm glad it helped ✌️

Collapse
 
mgecmez profile image
mgecmez

Hi Atta,

Thank you so much for this post.

I have a question. How to post typescript map object to .net core webapi?

Collapse
 
sirluis profile image
Luis Henrique

Actually Map.prototype.forEach does not behave like his array cousin. It returns a iterator.