JavaScript Map and Set Explained

Поделиться
HTML-код
  • Опубликовано: 7 окт 2024

Комментарии • 96

  • @felipeog
    @felipeog 3 года назад +51

    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

  • @qatadd8313
    @qatadd8313 4 года назад +4

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

  • @rahuls331
    @rahuls331 4 года назад +26

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

  • @deepakkaithwas8281
    @deepakkaithwas8281 4 года назад +9

    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.

  • @haydennharper7072
    @haydennharper7072 2 месяца назад

    So helpful and easy to understand with your explanations and example cases. Thank you!

  • @Karlponken
    @Karlponken 3 года назад +1

    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.

  • @b7otato
    @b7otato 4 года назад +20

    7:50 - map

  • @frankliva7438
    @frankliva7438 3 года назад

    the way youre explaining is so different. such clarity

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

  • @LiveEveryMoment_WithLOVE.
    @LiveEveryMoment_WithLOVE. 3 года назад

    Wow, no more search abt JS Set n Map, thank U so much Bro!👍

  • @bridgetfitzgerald7656
    @bridgetfitzgerald7656 3 года назад +12

    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 2 года назад +3

      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 2 года назад +2

      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 2 года назад +1

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

  • @veermetri05
    @veermetri05 4 года назад +4

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

  • @Nickdondo
    @Nickdondo 2 года назад

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

  • @centaur26
    @centaur26 3 года назад

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

  • @VishalGupta-jsdev
    @VishalGupta-jsdev 2 года назад +3

    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
    @fernandoesparragoza8765 4 года назад +7

    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 11 месяцев назад

      yea i was skipping back and forth looking for where he referenced the map value lol

  • @CastleShield
    @CastleShield 5 лет назад +7

    Well explained, thank you.

  • @rajeevpurohit23
    @rajeevpurohit23 2 года назад

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

  • @samueltorres2485
    @samueltorres2485 2 года назад +1

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

  • @benabernethy1405
    @benabernethy1405 2 года назад

    Thank you. Really appreciate this vid. Subbed!

  • @valikonen
    @valikonen 5 лет назад +19

    You miss very important aspect, how to loop over them.

    • @Samuel-wi1dh
      @Samuel-wi1dh 4 года назад +2

      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

  • @Capicuaman
    @Capicuaman 5 лет назад +3

    Great video, thank you.

  • @HolyGround777
    @HolyGround777 2 года назад

    This is a great introduction!!

  • @addicted2headway
    @addicted2headway 2 года назад

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

  • @lagiator
    @lagiator 5 лет назад +2

    thanks, keep uploading!

    • @javascriptmastery
      @javascriptmastery  5 лет назад +1

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

  • @longnhat6405
    @longnhat6405 Год назад

    nicely problem solution approach! keep it up

  • @saifulislamkhan6414
    @saifulislamkhan6414 4 года назад +1

    Awesome bro. Please keep it up.

  • @nan3776
    @nan3776 3 года назад

    You help me a lot. Thanks!

  • @ilearnwithstar4389
    @ilearnwithstar4389 Год назад

    explanation is awesome.

  • @blyfo
    @blyfo 2 года назад +1

    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

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

  • @faultfinderx
    @faultfinderx Год назад

    Thank you!

  • @think_cafe
    @think_cafe 4 месяца назад

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

  • @anilkatakam2738
    @anilkatakam2738 3 года назад +2

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

  • @rickdiculous23
    @rickdiculous23 3 года назад +1

    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?

  • @oncoding4520
    @oncoding4520 2 года назад

    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?

  • @danielmatei6858
    @danielmatei6858 5 лет назад +1

    Good lesson, thanks :)

  • @luanmotta4906
    @luanmotta4906 4 года назад +1

    Great video!

  • @sanchit8818
    @sanchit8818 4 года назад +2

    Great tutorial but watch it at 2x speed!

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

  • @zexsen85
    @zexsen85 5 лет назад +1

    nice video... very good explained :)

  • @aamirsuleman9815
    @aamirsuleman9815 3 года назад

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

  • @aswinbudhathoki6300
    @aswinbudhathoki6300 4 месяца назад

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

  • @ankitaaaaaaa25
    @ankitaaaaaaa25 4 года назад +1

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

  • @sanjanak7598
    @sanjanak7598 3 года назад

    Nice .

  • @fuka9676
    @fuka9676 4 года назад

    great video

  • @s1a2i3l4u5
    @s1a2i3l4u5 5 лет назад +1

    Thanks a lot

  • @vaibhavsharma3955
    @vaibhavsharma3955 3 года назад

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

  • @TanGuven
    @TanGuven 4 года назад +3

    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 года назад +1

      @@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 3 года назад

      @@TanGuven bro i tried it and the VScode only show the very last key if they are more than one with the same keys :)

  • @saputrauta09
    @saputrauta09 8 месяцев назад

    Thankyou

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

  • @meghalbisht6768
    @meghalbisht6768 4 года назад +1

    superrrrrrr!

  • @pie1337
    @pie1337 2 года назад

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

  • @chandiniudaykumar6628
    @chandiniudaykumar6628 Год назад

    How to delete non-primitive value from set?

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

  • @elenavetisyan1826
    @elenavetisyan1826 3 года назад

    How is it possible to change the const value?

  • @pravinchukkala545
    @pravinchukkala545 2 года назад

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

  • @anaghasalvi8364
    @anaghasalvi8364 4 года назад

    Helpful

  • @nhatkhoaphan971
    @nhatkhoaphan971 3 года назад

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

  • @mmrm3302
    @mmrm3302 2 года назад

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

  • @Nelzdgamer
    @Nelzdgamer 4 года назад +1

    i am a newbie on Js, please how do i get my vscode to show the console of my code

    • @rokonzamann
      @rokonzamann 4 года назад

      "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 4 года назад

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

  • @anonymousmasungsong6685
    @anonymousmasungsong6685 4 года назад

    What's the color theme?

  • @Tony.Nguyen137
    @Tony.Nguyen137 Год назад

    At 0:52 how did you copy paste the second console.log???

    • @mikeynavarro3195
      @mikeynavarro3195 Год назад +1

      it's a keyboard shortcut. on Mac if you hover over the line of code and press: shift , option , down arrow it'll duplicate.

  • @leg3ndtariq
    @leg3ndtariq 5 лет назад +1

    Can I hug you ? 😍

    • @DRKongo-vi8ok
      @DRKongo-vi8ok 3 года назад +1

      if he doesnt want to be hugged hug me

  • @jemesmemes9026
    @jemesmemes9026 3 года назад

    Maps start here 8:13

  • @iiimiiim
    @iiimiiim 5 лет назад +4

    console.log("Thanks!");

  • @athithyanGG
    @athithyanGG 3 года назад

    15:20 an

  • @teachhelphotline678
    @teachhelphotline678 3 года назад

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