JavaScript Map and Set Explained

  Рет қаралды 113,870

JavaScript Mastery

JavaScript Mastery

Күн бұрын

In this video we will look at some of the new data structures.
ES6 Introduced Maps and Sets to JavaScript. Understand difference between JavaScript objects and Maps and Sets and Arrays.

Пікірлер: 96
@felipeog
@felipeog 3 жыл бұрын
Set 3:10 add method 4:33 delete method 5:07 clear method 5:33 has method 6:00 size property Map 12:05 set method 12:57 delete method 13:45 clear method 14:04 has method 14:40 size property
@b7otato
@b7otato 4 жыл бұрын
7:50 - map
@qatadd8313
@qatadd8313 3 жыл бұрын
Man I Thank You Strongly For Make Everything Crystal Clear..
@Karlponken
@Karlponken 3 жыл бұрын
Thanks for the explanation! And from my understanding 'Set' is the best way to always ensure correct key order which a regular object can't rely on.
@rahuls331
@rahuls331 4 жыл бұрын
Your coding flow is nice. The smooth use of shortcuts and line movements are fantastic.
@javascriptmastery
@javascriptmastery 4 жыл бұрын
Glad you think so!
@deepakkaithwas8281
@deepakkaithwas8281 3 жыл бұрын
Nice video, please make one more for advance use of SET and MAP, covering more scenarios, where it should be used practically instead of any other data structure.
@frankliva7438
@frankliva7438 2 жыл бұрын
the way youre explaining is so different. such clarity
@LiveEveryMoment_WithLOVE.
@LiveEveryMoment_WithLOVE. 2 жыл бұрын
Wow, no more search abt JS Set n Map, thank U so much Bro!👍
@vijayyadavs
@vijayyadavs 3 жыл бұрын
Jaha pana Tusi Great ho :). A beginner like me in Javascripts. I was able to understand your map & set concepts and am able to implement the same in my code. working successfully. Thanks & God bless you
@teachhelphotline678
@teachhelphotline678 3 жыл бұрын
Thank you for this video!!! I finally know how to use a Map!!! :D
@benabernethy1405
@benabernethy1405 2 жыл бұрын
Thank you. Really appreciate this vid. Subbed!
@veermetri05
@veermetri05 4 жыл бұрын
Really nice explanation, thanks you. I expected to also learn Map.get.
@bridgetfitzgerald7656
@bridgetfitzgerald7656 2 жыл бұрын
Hi, adding all those empty objects to the map (at ~12:34) was a bit misleading. From my tests, I'm pretty sure that you would never have been able to run myMap.delete({}) or myMap.has({}) because each of those empty objects is stored at a different location in memory. So what's the point in creating them? You appeared to be showing that one of the advantages of Map compared to a regular object is that you can create duplicate keys in a map (i.e. multiple empty objects). But in fact ''duplicate" keys are NOT possible in myMap. In your example, each empty object you create as a key is a different thing in memory. And because you have created those keys without a reference to them in memory, i.e. being stored as a variable, once those keys are created, you can no longer access them using .has({}). Let me know if I'm wrong.
@lucahighton7648
@lucahighton7648 Жыл бұрын
Agreed. it would've been a much more realistic example if he had used two visibly different objects to prove his point. if you tried to do that with a regular object, you would end up with the key just being "[object Object]" for any arbitrary object, no matter it's properties. Still, everything he said was technically not wrong, but probably could've been made more clear by using a better example.
@anj000
@anj000 Жыл бұрын
There is a recurring meme in developers community about writing obfuscated code so that no one else can understand it and you become irreplaceable. I feel like people responsible for JS standards took that as a guideline and are introducing features that have possibility to make JS even harder and convoluted. And by this logic demand for JS developers will rise indefinitely. I really do not see a point in Sets and Maps. Why not introduce just a `unique` method on existing arrays? It will do the same thing as [... new Set()] without clutter that Set introduces. And I also do not see how benefits of Map outweighs possibility of writing convoluted code. Who do F needs objects as keys. This screams to me an overengineered solution.
@lucahighton7648
@lucahighton7648 Жыл бұрын
@@anj000 I have used objects as keys before. it is useful to work with data from a relational database
@JimmyKama
@JimmyKama Жыл бұрын
@@anj000 What's the point of making JS harder and convulated? Makes no sense. btw it's no private matter fater all...
@kiwi-Centaur
@kiwi-Centaur 2 жыл бұрын
thaks for this awesome tutorial, very helpful, cleared my confusion about sets and maps. thnks
@samueltorres2485
@samueltorres2485 2 жыл бұрын
A video with more practical examples would be great! Nice video!
@TomasSowellIsGreat
@TomasSowellIsGreat 2 жыл бұрын
This is a great introduction!!
@saifulislamkhan6414
@saifulislamkhan6414 4 жыл бұрын
Awesome bro. Please keep it up.
@CastleShield
@CastleShield 4 жыл бұрын
Well explained, thank you.
@javascriptmastery
@javascriptmastery 4 жыл бұрын
Thanks!
@rajeevpurohit23
@rajeevpurohit23 Жыл бұрын
Clear and concise! But you forgot to mention the get methods to get the value after setting
@lagiator
@lagiator 5 жыл бұрын
thanks, keep uploading!
@javascriptmastery
@javascriptmastery 5 жыл бұрын
Thank you soo much! As I'm just starting out, it really means a lot!
@nan3776
@nan3776 3 жыл бұрын
You help me a lot. Thanks!
@Capicuaman
@Capicuaman 5 жыл бұрын
Great video, thank you.
@javascriptmastery
@javascriptmastery 5 жыл бұрын
Thanks you.
@VishalGupta-jsdev
@VishalGupta-jsdev 2 жыл бұрын
For your information, you can not store multiple same keys of type number or string in MAP. Multiple same keys can only work with non-primitive datatype , when set as a key
@danielmatei6858
@danielmatei6858 4 жыл бұрын
Good lesson, thanks :)
@longnhat6405
@longnhat6405 Жыл бұрын
nicely problem solution approach! keep it up
@Nickdondo
@Nickdondo 2 жыл бұрын
lol I needed this video 5 hours ago before my technical assessment.
@fernandoesparragoza8765
@fernandoesparragoza8765 3 жыл бұрын
Also, you can use get() to get the value from a Map property by its key.
@kasra8106
@kasra8106 Жыл бұрын
Probably the most important one lol
@nicholasc.5944
@nicholasc.5944 7 ай бұрын
yea i was skipping back and forth looking for where he referenced the map value lol
@ihtshammir3733
@ihtshammir3733 Ай бұрын
Simple spot on.
@ilearnwithstar4389
@ilearnwithstar4389 Жыл бұрын
explanation is awesome.
@faultfinderx
@faultfinderx Жыл бұрын
Thank you!
@addicted2headway
@addicted2headway 2 жыл бұрын
Please make a more videos on Javascript. Which will help to solve Data structures and algorithms problems
@fuka9676
@fuka9676 3 жыл бұрын
great video
@oncoding4520
@oncoding4520 Жыл бұрын
nice vide, finally i got it the difference and why it is useful. may i ask you what is that extension with the rocket down below that it says 2.3h? is like a focus mode activated?
@luanmotta4906
@luanmotta4906 4 жыл бұрын
Great video!
@javascriptmastery
@javascriptmastery 4 жыл бұрын
Thanks!
@zexsen85
@zexsen85 4 жыл бұрын
nice video... very good explained :)
@javascriptmastery
@javascriptmastery 4 жыл бұрын
Thank you!
@blyfo
@blyfo 2 жыл бұрын
Thanks for the video. But, in the Map, why would you want to have an empty object as the key? How would you access that item in the Map
@girlandhercomputer7204
@girlandhercomputer7204 4 жыл бұрын
Thank you for your explanation and examples they are very useful, I also read the doc but your explanation makes things a lot easier~ Great thanks, one sub for ya~
@sanjanak7598
@sanjanak7598 3 жыл бұрын
Nice .
@knightfallgame
@knightfallgame 3 жыл бұрын
so maps can hold any value as either the key or value from what ive read. which means the key itself can be any primitive value or object. im having trouble understanding what the use case would be for using an object as a key? i just cant seem to wrap my brain around it was wondering if you had any insight?
@anaghasalvi8364
@anaghasalvi8364 4 жыл бұрын
Helpful
@valikonen
@valikonen 4 жыл бұрын
You miss very important aspect, how to loop over them.
@Samuel-wi1dh
@Samuel-wi1dh 3 жыл бұрын
looping over an object isn't specific to Maps/Sets
@zacharywallace8067
@zacharywallace8067 Жыл бұрын
Deconstruct into an array and loop over said array [...myMap].forEach(value => {...})
@lutfiikbalmajid
@lutfiikbalmajid Жыл бұрын
forEach
@s1a2i3l4u5
@s1a2i3l4u5 5 жыл бұрын
Thanks a lot
@javascriptmastery
@javascriptmastery 5 жыл бұрын
No problem.
@anilkatakam2738
@anilkatakam2738 3 жыл бұрын
Can you explain map delete with multiple empty objects as keys?
@aamirsuleman9815
@aamirsuleman9815 3 жыл бұрын
add the map.get method explanation... good work!
@sanchit8818
@sanchit8818 4 жыл бұрын
Great tutorial but watch it at 2x speed!
@saputrauta09
@saputrauta09 5 ай бұрын
Thankyou
@think_cafe
@think_cafe Ай бұрын
Can you make video on set key,values and entries methods?
@ankitaaaaaaa25
@ankitaaaaaaa25 3 жыл бұрын
Great 👍you should make a series "data structures using js"
@javascriptmastery
@javascriptmastery 3 жыл бұрын
Great idea!
@bobbysilver272
@bobbysilver272 Жыл бұрын
2:06 It's amazing as a beginner trying to learn javascript, how often a decent video gets ruined because the teacher uses a term that is totally new without explaining it. So many people that know how to do something don't actually know how to tech things to beginners because they use terms that are more advanced.
@pravinchukkala545
@pravinchukkala545 Жыл бұрын
Hi, I have one query. how can we delete non-primitive values from set
@meghalbisht6768
@meghalbisht6768 4 жыл бұрын
superrrrrrr!
@javascriptmastery
@javascriptmastery 4 жыл бұрын
Thanks!
@TanGuven
@TanGuven 4 жыл бұрын
If i have 2 same key in the map and if i delete with the key what would happen?
@quanlili1157
@quanlili1157 4 жыл бұрын
Impossible to have 2 same key.
@TanGuven
@TanGuven 4 жыл бұрын
@@quanlili1157 Are you sure, you've watched the video. The answer should be, "it would delete both keys". So, watch it and you will say at the end, WTF
@snehashischattopadhyay9519
@snehashischattopadhyay9519 4 жыл бұрын
@@TanGuven you can't have two same key in the same map.
@ilovepizza8263
@ilovepizza8263 2 жыл бұрын
@@TanGuven bro i tried it and the VScode only show the very last key if they are more than one with the same keys :)
@vaibhavsharma3955
@vaibhavsharma3955 3 жыл бұрын
How we can maintain set of unique objects? Javascript doesn't have equals method as Java to compare objects. right?
@pie1337
@pie1337 2 жыл бұрын
im confuse. i thought const cannot be reassigned. how can you use add and delete ?
@patrikshane7981
@patrikshane7981 2 жыл бұрын
how to delete object inside of [1, 2, 3, 4, 6, {id: 7}] i wanna achieve to delete object {id: 7 } with Set delete method, i would be like this mySet.delete({id: 7}) is it right ?
@elenavetisyan1826
@elenavetisyan1826 2 жыл бұрын
How is it possible to change the const value?
@davivify
@davivify 2 жыл бұрын
I guess I don't get the value of a _set_ object. Surely it has to have more than just being unique. It'd be easy enough to write a method to remove redundant entries from an array. Where are the methods for doing set intersection, union, and subtraction, for instance? In _set theory,_ you use these operations all the time.
@Tony.Nguyen137
@Tony.Nguyen137 Жыл бұрын
At 0:52 how did you copy paste the second console.log???
@mikeynavarro3195
@mikeynavarro3195 Жыл бұрын
it's a keyboard shortcut. on Mac if you hover over the line of code and press: shift , option , down arrow it'll duplicate.
@evidnelz3628
@evidnelz3628 4 жыл бұрын
i am a newbie on Js, please how do i get my vscode to show the console of my code
@r0mankon
@r0mankon 3 жыл бұрын
"vscode to show the console of my code" wtf?? may be you mean the node command, install nodejs on computer for executing js like that.
@GooseGumlizzard
@GooseGumlizzard 3 жыл бұрын
@@r0mankon I think he means the integrated terminal in vscode
@revatib908
@revatib908 3 жыл бұрын
There is an extension called 'Code Runner'. Install it and you will see a 'play' icon to the extreme right . Just open terminal and results would be seen there .
@aswinbudhathoki6300
@aswinbudhathoki6300 23 күн бұрын
You forgot ‘get’ function in Map to get the value from the key like myMap.get(1) will output ‘one’.
@jemesmemes9026
@jemesmemes9026 3 жыл бұрын
Maps start here 8:13
@anonymousmasungsong6685
@anonymousmasungsong6685 3 жыл бұрын
What's the color theme?
@leg3ndtariq
@leg3ndtariq 4 жыл бұрын
Can I hug you ? 😍
@DRKongo-vi8ok
@DRKongo-vi8ok 3 жыл бұрын
if he doesnt want to be hugged hug me
@nhatkhoaphan971
@nhatkhoaphan971 3 жыл бұрын
but why would i want to map an empty object to a value?
@chandiniudaykumar6628
@chandiniudaykumar6628 Жыл бұрын
How to delete non-primitive value from set?
@iiimiiim
@iiimiiim 4 жыл бұрын
console.log("Thanks!");
@mmrm3302
@mmrm3302 Жыл бұрын
Still couldn't understand what's the real life advantage of Map comparing to Object 🤔
@athithyarj7216
@athithyarj7216 2 жыл бұрын
15:20 an
Урок 13. JavaScript. Все о Map, Set, WeakMap, WeakSet с примерами
40:03
Владилен Минин
Рет қаралды 150 М.
Map vs Object in JavaScript
14:33
Leigh Halliday
Рет қаралды 21 М.
Stupid Barry Find Mellstroy in Escape From Prison Challenge
00:29
Garri Creative
Рет қаралды 20 МЛН
I’m just a kid 🥹🥰 LeoNata family #shorts
00:12
LeoNata Family
Рет қаралды 16 МЛН
ИРИНА КАЙРАТОВНА - АЙДАХАР (БЕКА) [MV]
02:51
ГОСТ ENTERTAINMENT
Рет қаралды 4 МЛН
JavaScript Best Practices and Coding Conventions - Write Clean Code
28:06
JavaScript Mastery
Рет қаралды 81 М.
Complete Guide to JS Sets: How They Work & When To Use Them
18:38
Top 10 JavaScript Array Methods
15:52
JavaScript Mastery
Рет қаралды 9 М.
Hash Tables - Beau teaches JavaScript
9:50
freeCodeCamp.org
Рет қаралды 91 М.
JavaScript Crash Course 2021 - Master JavaScript in One Video!
2:08:59
JavaScript Mastery
Рет қаралды 242 М.
map, filter & reduce 🙏 Namaste JavaScript Ep. 19 🔥
37:42
Akshay Saini
Рет қаралды 856 М.
You Should Use Maps and Sets in JS
14:28
Syntax
Рет қаралды 8 М.
Maps vs. Objects in JavaScript - What's the Difference?
11:48
How to Implement a Hash Table in JavaScript
25:39
Ben Awad
Рет қаралды 102 М.
Map, Set, WeakMap & WeakSet in JavaScript - Real use case
12:20
1$ vs 500$ ВИРТУАЛЬНАЯ РЕАЛЬНОСТЬ !
23:20
GoldenBurst
Рет қаралды 741 М.
Asus  VivoBook Винда за 8 часов!
1:00
Sergey Delaisy
Рет қаралды 1 МЛН
Неразрушаемый смартфон
1:00
Status
Рет қаралды 1,6 МЛН
Lid hologram 3d
0:32
LEDG
Рет қаралды 6 МЛН