Maps vs. Objects in JavaScript - What's the Difference?

preview_player
Показать описание
In today's video, we will look at the difference between Maps and Objects in JavaScript. You may be more familiar with objects, but both data structures allow you to store key-value pairs in JavaScript but with some key differences.

Converting a Map to JSON:

If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!

#dcode #javascript
Рекомендации по теме
Комментарии
Автор

Also it's possible to use Object.entries() for your loop case and get the benefit of destructuring as for the Map example
for (let [k, v] of Object.entries(o)) {
console.log(k, '=>', v)
}

rmnkot
Автор

5:20 I'm currently exploring solutions to create a huge booking calendar and I've tried using dayjs objects as keys (with data held by any date as value) and it works wonders so far.

nicolashumbert
Автор

To stringify a Map jou can create an Object from the Map's entries (it might only work with stringy keys)

samuelmoncarey
Автор

Also the thing with Maps, you are guaranteed order in the order of insertion. you wont get that with objects.

dennisorbison
Автор

You are amazing brother! Thanks for sharing for knowledge with us! I am surprised that this channel is so underrated! I am taking your rust course right now and it's one of the best and I am going to share it with my team as the only playlist they ever need to learn rust! Thanks again! Keep up the amazing work!

danielnadar
Автор

IMHO Maps work best for data structures with 2 or more dimensions.
In the example above it would be difficult to have an indexed collection of PersonObjects because name is not suitable as a primary key..
I use Maps for in-memory databases with unique keys that link to rows in a form. Keys are generally Base36(time()) which make them unique

montebont
Автор

Explained very well but it would have been more better if you could atleast show an example of map's usecase.. although loved the explanation ❤

souravrouth
Автор

you need to give practical examples, about using Maps, use cases . Very cool video thanks mate

moe
Автор

how do Maps work with typescript? and can be they turned into JSON?

maccodifavole
Автор

Well I didn't see the benefits of the Map, actually I am more convinced to use regular Objects now 😅

goldmikanik
welcome to shbcf.ru