You Should Use Maps and Sets in JS

  Рет қаралды 8,728

Syntax

Syntax

Күн бұрын

In this video CJ talks about the scenarios when it is better to use Maps and Sets instead of Objects and Arrays in JavaScript.
00:00 Intro
01:09 The problem with Objects
02:41 When to use a Map
03:07 How to use Map
04:34 Create a Map from an Object
04:59 Object Keys are Strings
05:59 Create a Map from an Array
07:02 Map methods are nice
07:45 JSON.stringify a Map
08:53 Sets
09:15 The problem with Array.includes
10:36 Making a Set with an Object
11:50 Create a Set from an Array
12:23 Sets and Duplicate Values
12:58 Set methods on MDN
13:21 Thanks for watching
Listen to episode 689 on Syntax: syntax.fm/show/689/you-should...
Read about Map on MDN: developer.mozilla.org/en-US/d...
Read about Set on MDN: developer.mozilla.org/en-US/d...
------------------------------------------------------------------------------
Hit us up on Socials!
www.syntax.fm/links
Brought to you by Sentry, use code tastytreats to get your first 2 months free: sentry.io/syntax/
#javascript #webdevelopment #programming #typescript

Пікірлер: 31
@syntaxfm
@syntaxfm 4 ай бұрын
Listen to Syntax episode 689: syntax.fm/show/689/you-should-be-using-javascript-maps-and-sets Are you using Maps and Sets in your code? Let us know! 👇
@benvinegar
@benvinegar 4 ай бұрын
Years of muscle memory have made it hard to not use Objects all the time, so this was a helpful illustration of why I should use Map and Set more often. Thanks CJ.
@Dedseq
@Dedseq 4 ай бұрын
precisely my thoughts
@TheOllieJT
@TheOllieJT 4 ай бұрын
Must be daunting to join Syntax after such a long time of just Scot & Wes... you're doing a great job, CJ!
@CodingGarden
@CodingGarden 4 ай бұрын
Thank you 🙏 - It's a big role to fill but the team is super collaborative, encouraging and allowing me to do some of my best work.
@coltonaallen
@coltonaallen 4 ай бұрын
Great vid, CJ! Welcome to The Syntax team! My literal 3 favorite devs now in one place! Couldn't ask for any meter trio!
@studiousllama4776
@studiousllama4776 4 ай бұрын
This was awesome! Loving the deep dive and hoping for more videos like it
@syntaxfm
@syntaxfm 4 ай бұрын
More coming 🔜
@jagonza2000
@jagonza2000 4 ай бұрын
Great video CJ!
@btrsl
@btrsl 4 ай бұрын
Yesss! This is what we want 🎉🎉
@CodingGarden
@CodingGarden 4 ай бұрын
😄
@pranjalagnihotri6072
@pranjalagnihotri6072 4 ай бұрын
Hey CJ, please make a video on using different design patterns in JavaScript and where to use them 😊
@CodingGarden
@CodingGarden 4 ай бұрын
This is a good topic! I'll put it on the list.
@___dh__dh__
@___dh__dh__ Ай бұрын
It would be interesting to know scenarios where set/map doesn't actually make sense and objects might be better.
@gosnooky
@gosnooky 4 ай бұрын
One of the unfortunate things about the Set implementation in JS is that it can only match primitives and memory addresses to compute equality. So even if you have two objects with the exact same fields and values, they will still not be equal because each has a non-unique memory address. Just something to be aware of if you're coming from a language like Java where you can override the 'equals' method on any object to govern how equality is computed.
@Pra2wins
@Pra2wins 4 ай бұрын
CJ ❤
@prashlovessamosa
@prashlovessamosa 4 ай бұрын
👍 CJ
@jofftiquez
@jofftiquez 4 ай бұрын
May I know what plugin does that automatic logging on the end of your `console.log()`? Thanks
@syntaxfm
@syntaxfm 4 ай бұрын
It is called quokka.js There is also a plugin called TypeScript Worksheet that is similar, but I have not tried it.
@user-xr3hf2ps6p
@user-xr3hf2ps6p 3 ай бұрын
May I know what color theme you have on vs code?
@syntaxfm
@syntaxfm 3 ай бұрын
You can see the theme I use here: github.com/codinggarden/vscode-settings?tab=readme-ov-file#themescolor -CJ
@user-xr3hf2ps6p
@user-xr3hf2ps6p 3 ай бұрын
@@syntaxfm ☺️thank you very much
@Souljacker7
@Souljacker7 2 ай бұрын
Any of you guys know what extension is that that shows the result in the side?
@syntaxfm
@syntaxfm 2 ай бұрын
It is called Quokkajs - quokkajs.com/
@jonathonbloomfield8991
@jonathonbloomfield8991 4 ай бұрын
Thank you for this video! Would you mind sharing how you're displaying logs and return values inline in your code editor please?
@Mike-vq3yt
@Mike-vq3yt 4 ай бұрын
Quokka.js maybe?
@CodingGarden
@CodingGarden 4 ай бұрын
Using quokka.js there is also an extension called TypeScript worksheet that I haven't tried yet.
@BartekKozera
@BartekKozera Күн бұрын
Hot take: The "problems" with using objects are not real problems and they never come up in real life scenarios so it's not worth sacrifising the nice syntax of object for the verbosity of using Map.
@syntaxfm
@syntaxfm Күн бұрын
It's one of those "use it when you have those problems " kinda thing. Not that they should replace objects in your day to day.
@good_eats876
@good_eats876 4 ай бұрын
js is so quirky, it’s insane
@lautarodapin
@lautarodapin 4 ай бұрын
the lesson is, use typescript
Set up a Mac in 2024 for Power Users and Developers
1:00:34
Syntax
Рет қаралды 267 М.
Maps vs. Objects in JavaScript - What's the Difference?
11:48
Was ist im Eis versteckt? 🧊 Coole Winter-Gadgets von Amazon
00:37
SMOL German
Рет қаралды 36 МЛН
That's how money comes into our family
00:14
Mamasoboliha
Рет қаралды 9 МЛН
Wait for the last one! 👀
00:28
Josh Horton
Рет қаралды 158 МЛН
Modern JS Toolchains (Biome, Oxc + More)
47:52
Syntax
Рет қаралды 3,5 М.
Finally Fix Your Issues With JS/React Memory Management 😤
20:13
Jack Herrington
Рет қаралды 82 М.
The Most Important Skill You Never Learned
34:56
Web Dev Simplified
Рет қаралды 172 М.
Hands On Docker Examples for Developers
49:35
Syntax
Рет қаралды 10 М.
STOP Using Classes In JavaScript | Prime Reacts
14:02
ThePrimeTime
Рет қаралды 225 М.
The Ultimate Guide to JavaScript Collections
24:52
Bran van der Meer
Рет қаралды 2,6 М.
20+ Must Know Array Methods That Almost Nobody Knows
11:47
Web Dev Simplified
Рет қаралды 87 М.
We can now transition to and from display: none
21:20
Kevin Powell
Рет қаралды 82 М.
100+ Linux Things you Need to Know
12:23
Fireship
Рет қаралды 710 М.
Хотела заскамить на Айфон!😱📱(@gertieinar)
0:21
Взрывная История
Рет қаралды 6 МЛН
Игровой Комп с Авито за 4500р
1:00
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 2,1 МЛН
1$ vs 500$ ВИРТУАЛЬНАЯ РЕАЛЬНОСТЬ !
23:20
GoldenBurst
Рет қаралды 1,6 МЛН