JavaScript Map and Set Explained

Ғылым және технология

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
    @felipeog3 жыл бұрын

    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
    @b7otato4 жыл бұрын

    7:50 - map

  • @qatadd8313
    @qatadd83133 жыл бұрын

    Man I Thank You Strongly For Make Everything Crystal Clear..

  • @rahuls331
    @rahuls3314 жыл бұрын

    Your coding flow is nice. The smooth use of shortcuts and line movements are fantastic.

  • @javascriptmastery

    @javascriptmastery

    4 жыл бұрын

    Glad you think so!

  • @frankliva7438
    @frankliva74382 жыл бұрын

    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!👍

  • @Karlponken
    @Karlponken3 жыл бұрын

    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.

  • @deepakkaithwas8281
    @deepakkaithwas82813 жыл бұрын

    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.

  • @vijayyadavs
    @vijayyadavs3 жыл бұрын

    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
    @teachhelphotline6783 жыл бұрын

    Thank you for this video!!! I finally know how to use a Map!!! :D

  • @benabernethy1405
    @benabernethy14052 жыл бұрын

    Thank you. Really appreciate this vid. Subbed!

  • @kiwi-Centaur
    @kiwi-Centaur2 жыл бұрын

    thaks for this awesome tutorial, very helpful, cleared my confusion about sets and maps. thnks

  • @CastleShield
    @CastleShield4 жыл бұрын

    Well explained, thank you.

  • @javascriptmastery

    @javascriptmastery

    4 жыл бұрын

    Thanks!

  • @veermetri05
    @veermetri054 жыл бұрын

    Really nice explanation, thanks you. I expected to also learn Map.get.

  • @bridgetfitzgerald7656
    @bridgetfitzgerald76562 жыл бұрын

    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...

  • @saifulislamkhan6414
    @saifulislamkhan64144 жыл бұрын

    Awesome bro. Please keep it up.

  • @nan3776
    @nan37763 жыл бұрын

    You help me a lot. Thanks!

  • @TomasSowellIsGreat
    @TomasSowellIsGreat2 жыл бұрын

    This is a great introduction!!

  • @Capicuaman
    @Capicuaman5 жыл бұрын

    Great video, thank you.

  • @javascriptmastery

    @javascriptmastery

    5 жыл бұрын

    Thanks you.

  • @samueltorres2485
    @samueltorres24852 жыл бұрын

    A video with more practical examples would be great! Nice video!

  • @Nickdondo
    @Nickdondo2 жыл бұрын

    lol I needed this video 5 hours ago before my technical assessment.

  • @longnhat6405
    @longnhat6405 Жыл бұрын

    nicely problem solution approach! keep it up

  • @danielmatei6858
    @danielmatei68584 жыл бұрын

    Good lesson, thanks :)

  • @rajeevpurohit23
    @rajeevpurohit23 Жыл бұрын

    Clear and concise! But you forgot to mention the get methods to get the value after setting

  • @VishalGupta-jsdev
    @VishalGupta-jsdev2 жыл бұрын

    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

  • @fernandoesparragoza8765
    @fernandoesparragoza87653 жыл бұрын

    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

  • @lagiator
    @lagiator5 жыл бұрын

    thanks, keep uploading!

  • @javascriptmastery

    @javascriptmastery

    5 жыл бұрын

    Thank you soo much! As I'm just starting out, it really means a lot!

  • @ilearnwithstar4389
    @ilearnwithstar4389 Жыл бұрын

    explanation is awesome.

  • @knightfallgame
    @knightfallgame3 жыл бұрын

    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?

  • @blyfo
    @blyfo2 жыл бұрын

    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

  • @zexsen85
    @zexsen854 жыл бұрын

    nice video... very good explained :)

  • @javascriptmastery

    @javascriptmastery

    4 жыл бұрын

    Thank you!

  • @faultfinderx
    @faultfinderx Жыл бұрын

    Thank you!

  • @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?

  • @ihtshammir3733
    @ihtshammir3733Ай бұрын

    Simple spot on.

  • @addicted2headway
    @addicted2headway2 жыл бұрын

    Please make a more videos on Javascript. Which will help to solve Data structures and algorithms problems

  • @luanmotta4906
    @luanmotta49064 жыл бұрын

    Great video!

  • @javascriptmastery

    @javascriptmastery

    4 жыл бұрын

    Thanks!

  • @fuka9676
    @fuka96763 жыл бұрын

    great video

  • @anilkatakam2738
    @anilkatakam27383 жыл бұрын

    Can you explain map delete with multiple empty objects as keys?

  • @sanjanak7598
    @sanjanak75983 жыл бұрын

    Nice .

  • @s1a2i3l4u5
    @s1a2i3l4u55 жыл бұрын

    Thanks a lot

  • @javascriptmastery

    @javascriptmastery

    5 жыл бұрын

    No problem.

  • @anaghasalvi8364
    @anaghasalvi83644 жыл бұрын

    Helpful

  • @girlandhercomputer7204
    @girlandhercomputer72044 жыл бұрын

    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~

  • @pravinchukkala545
    @pravinchukkala545 Жыл бұрын

    Hi, I have one query. how can we delete non-primitive values from set

  • @saputrauta09
    @saputrauta094 ай бұрын

    Thankyou

  • @valikonen
    @valikonen4 жыл бұрын

    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

  • @vaibhavsharma3955
    @vaibhavsharma39553 жыл бұрын

    How we can maintain set of unique objects? Javascript doesn't have equals method as Java to compare objects. right?

  • @patrikshane7981
    @patrikshane79812 жыл бұрын

    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 ?

  • @think_cafe
    @think_cafe19 күн бұрын

    Can you make video on set key,values and entries methods?

  • @sanchit8818
    @sanchit88184 жыл бұрын

    Great tutorial but watch it at 2x speed!

  • @aamirsuleman9815
    @aamirsuleman98153 жыл бұрын

    add the map.get method explanation... good work!

  • @pie1337
    @pie13372 жыл бұрын

    im confuse. i thought const cannot be reassigned. how can you use add and delete ?

  • @elenavetisyan1826
    @elenavetisyan18262 жыл бұрын

    How is it possible to change the const value?

  • @TanGuven
    @TanGuven4 жыл бұрын

    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

    3 жыл бұрын

    @@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 :)

  • @ankitaaaaaaa25
    @ankitaaaaaaa253 жыл бұрын

    Great 👍you should make a series "data structures using js"

  • @javascriptmastery

    @javascriptmastery

    3 жыл бұрын

    Great idea!

  • @anonymousmasungsong6685
    @anonymousmasungsong66853 жыл бұрын

    What's the color theme?

  • @nhatkhoaphan971
    @nhatkhoaphan9712 жыл бұрын

    but why would i want to map an empty object to a value?

  • @aswinbudhathoki6300
    @aswinbudhathoki630012 күн бұрын

    You forgot ‘get’ function in Map to get the value from the key like myMap.get(1) will output ‘one’.

  • @meghalbisht6768
    @meghalbisht67684 жыл бұрын

    superrrrrrr!

  • @javascriptmastery

    @javascriptmastery

    4 жыл бұрын

    Thanks!

  • @evidnelz3628
    @evidnelz36284 жыл бұрын

    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 .

  • @davivify
    @davivify2 жыл бұрын

    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.

  • @chandiniudaykumar6628
    @chandiniudaykumar6628 Жыл бұрын

    How to delete non-primitive value from set?

  • @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.

  • @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.

  • @jemesmemes9026
    @jemesmemes90263 жыл бұрын

    Maps start here 8:13

  • @leg3ndtariq
    @leg3ndtariq4 жыл бұрын

    Can I hug you ? 😍

  • @DRKongo-vi8ok

    @DRKongo-vi8ok

    3 жыл бұрын

    if he doesnt want to be hugged hug me

  • @iiimiiim
    @iiimiiim4 жыл бұрын

    console.log("Thanks!");

  • @mmrm3302
    @mmrm3302 Жыл бұрын

    Still couldn't understand what's the real life advantage of Map comparing to Object 🤔

  • @athithyarj7216
    @athithyarj72162 жыл бұрын

    15:20 an

Келесі