JavaScript for..in Loops

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

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

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

    best "for in loops" video so far. Cleared up confusions i had from watching other tutorials.

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

    I am a new Dev and this video was the most helpful I've seen, thank you!

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

    This is by far the best and simplest explanation of this concept. THANK YOU

  • @ShotgunMechanic
    @ShotgunMechanic 4 года назад +14

    I know this video is old but I really love the way you teach, you make things so easy to understand! I was having such a hard time with this but this video cleared things up in less than 8min!

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

    I've watched many other recent videos about for in loops and this is the only video that made me understand this concept. Thanks a lot!

  • @MasterZiomekPL
    @MasterZiomekPL 6 лет назад +10

    over 30 minutes of looking for an anwser. Thank you, Sir.

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

    3:22 "...can't do the dot notation because this is a variable, it's not a string...these have different names, so this is a variable that's holding those three values, one at a time..."
    This is exactly what I was looking for, thanks for posting!

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

    I was having a hard time wrapping my head around the concept, but you made it so easy! THANK YOU SO MUCH!

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

    Wow! This was extremely helpful. I love your teaching style and pace--just perfect. Thank you very much!

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

    you make it so easy to understand. even if i know some topics i go through your video anyway and i end up either learning more deeply or things that weren't so clear before finally make sense. please keep teaching, you're really good at it. Thank you steve.

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

    I wonder why not so many watching this. This is excellent. Thanks

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

    Your channel is a hidden gem man

  • @kubkato
    @kubkato 5 лет назад

    Subscribed after just watching this video. You gave a very clear explanation on the for...in loop in just 7 mins! Thank you!!!

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

    you make it easy to understand and have a very soothing voice! thank you

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

    I'm having a struggle with my programming learning process since I'm self-taught programmer but I think I just found a better way of doing it. I just wish that I could be someone decent like you sir...

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

    Yet another awesome tutorial! Cheers!

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

    Thank you very much for explaining difference in looping through arrays and object in a way everyone can understand. your tutorials have a riveting effect that many are addicted.

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

    Awesome tutorials.. You are helping me a lot. Thanks

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

    Thank you for this. You have a real calm way of explaining this. Much appreciated.

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

      I'm trying to learn JavaScript now. I find that I get stuck on things and spend ages trying to figure it out. Any advice?

  • @jp-hz6br
    @jp-hz6br 4 года назад

    Brilliant video - thanks for explaining the for in loop really simply!

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

    Thank you for your explanation for monster [prop]. I dont really understand the use for the bracket before and now i do.

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

    Haven't watched it yet but I gotta pay homage to the Sensei.
    At this rate, Imma owe you royalties when I get hired

  • @pablo.dm3
    @pablo.dm3 3 года назад

    Great job sir, it is very clear to understand the way you explain it .

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

    Thank You Steve, I have better understanding after watching your video...

  • @BaraqCodes
    @BaraqCodes 20 дней назад

    This playlist is golden

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

    this is great, thank you. i was recommended to your channel by a random youtuber :-)

  • @aruppanda9800
    @aruppanda9800 5 лет назад

    Your explanation is just awesome...

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

    Brilliant tutorials !!!

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

    6:11 Note, when you use for...in loops on arrays, the index num (prop in Steve's code) is returned as a string, not an integer.
    '0'
    '1'
    '2'
    etc
    This can affect you if you're going to do some math with the index number.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 года назад +2

      With a for...in loop you are going to get the property name, regardless of whether you are looping through an array or object. All the names will be treated as strings.
      You can use parseInt to convert the string to an integer OR use the simple for loop if you want a numerical index for the array.

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

      @@SteveGriffith-Prof3ssorSt3v3 "With a for...in loop you are going to get the property name, regardless of whether you are looping through an array or object."
      But i thought arrays don't have "property names", only indexes.
      thx

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

    Nice explanation sir

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

    Thank you! This is a great explanation, I could easily understand everything

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

    clear as crystal, You Are AMAZING Thats For Sure

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

    Thank you for such a beautiful explanation!

  • @camilogarcia1325
    @camilogarcia1325 5 лет назад

    Despite is for 2016 this is very helpful in 2019, thanks for taking the time to explain

  • @ChrisTian-ox5nr
    @ChrisTian-ox5nr 4 года назад

    Thank you very much!! This cleared out so much ambiguity for me. Makes perfects sense now!! You are Zbest!!

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

    very clear and simple. Thanks!

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

    Very informative! Thank you.

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

    Thank you! This specifically was hard to understand just from documentation

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

    You just saved me from losing my mind lol!! Thanks for the great help👍

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

    Nicely explained. So we have to memorize that prop in the first place is prop for object property, and when used inside of obj[ prop] it is a prop for value.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 года назад +1

      Yes. the first variable inside the parentheses will represent the number of each of the indexes in the array or property names in an object. You can call it whatever you want though.
      for( let cheeseburger in myObject ){
      console.log( cheeseburger, myObject[cheeseburger] );
      }

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

    Great content, your serie really is javascript zero to hero.
    one note thou, instead of let, const can be used because scope of declared variable is not outside of loop but inside.

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

    Any chance you have a beginner playlist of more videos like this? You explained it better than the premium courses I'm paying for.

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

    How are these not the most popular code videos on the YT?

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

    5:40 , best explaination

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

    so helpful! you are the best!

  • @Youssef-lv6wp
    @Youssef-lv6wp 4 года назад

    Thanks you for information

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

    I must admit this was not a good day. I was in the "Trough of Sorrows" and went on the internet prowl for some clarity. I found your explanation of for..in loops and got a badly needed :bulb: moment.💡

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

    Ty from Brazil.

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

    best of the best thanks professor👌♥ it'll be even better if you could teach for...of loops too thanks again

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  Год назад

      ruclips.net/video/wc4jMuumqLM/видео.html
      and the playlist for loops:
      ruclips.net/video/CidzYW-8I7s/видео.html

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

    Thank you very much, great explanation!

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

    I read that the for in loop has disadvantage especially one cannot depend on the seeming orderliness of iteration, at least in a cross-browser setting. Could you clarify the short coming with using the for in loop?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  3 года назад

      I have never run into an issue where an Array was not iterated in the order of the indexes.
      However, when iterating through an iterable object there are other processes that can impact that order. If you are looping through an object that has a custom iterator, it is the iterator that controls the order.
      Some objects are live and their contents can change while you are looping.
      This might give you more insight - ruclips.net/video/HZjvoftRvGE/видео.html

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

    Yep, very clear!

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

    no formation without repetition, second round makes me feel better. Thank you.

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

    Thanks for making this dude

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

    thank you Lord Steve .

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

    [
    { name: 'Woody', type: 'dog', age: 14 },
    { name: 'Bob', type: 'cat', age: 2, hungry: true, color: 'white' },
    { name: 'Roxy', type: 'dog', age: 5 },
    ]
    how to use for in loop or which loop we should use to get the name ?

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

      props[pets].name ... i have got it thanks a lot sir

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

    Love the sound in the end, boom, boom, boom :D

  • @brankoblesicjr.5792
    @brankoblesicjr.5792 5 лет назад

    Thanks dude. You help me a lot to understand this :)

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

    Thank you for the tutorial! Quick question: Why would we not have a length property here? Just out of curiosity, I don't really understand that. Thanks!

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 года назад

      Arrays have a length. Objects have properties with different qualities. Some can be looped over (iterable or enumerable) others can't. Objects also inherit properties through the prototype chain. So, Objects don't have a length. Their properties also don't have a numbered sequence. There is no index number for any Object property.

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

      @@SteveGriffith-Prof3ssorSt3v3 when the objects are nested inside an array, do they have the length property then?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 года назад

      @@harrietiluekhabho9795 objects don't have a length property

  • @ryantanjaya5854
    @ryantanjaya5854 5 лет назад

    very very helpful tutorial

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

    thank you for this video!

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

    Thanks bro😘

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

    Thank You Sir

  • @MiguelMartinez-hm9wk
    @MiguelMartinez-hm9wk 5 лет назад

    Why does prop return the keys of the array? Prop could have been anything but it 'knew' to get the property name and not the whole property [key : val]. Thanks for the videos!

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

    Merci beaucoup !!!!

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

    are they still usable after es6? is there a way to do it with modern array methods?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 года назад

      ES6 was a bunch of new things added to JS. Just like ES7 and 8 and soon 9. For...in loops are a core language feature. They wont ever be removed.

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

    How would one log a single value within an object? Say you only wanted to console log the "Nepal : 'Yeti'" property.

  • @Aditya-xz5qv
    @Aditya-xz5qv 4 года назад

    Thank you 🙂

  • @AE-yr6mo
    @AE-yr6mo 4 года назад

    Have you tried to do a For In loop when trying to access objects that have multiple layers?
    //e.g.
    for(item in object){
    console.log( item.prop)
    }
    //where :
    object = { item1 : {prop : 1}, item2 : {prop : 2}}
    //why does this give undefined values? Ideally 1 and 2 should be logged...not undefined.
    //is it something to do with closures or something to do with how the loop stores the object?
    //btw awesome to see you're still active on the video years on

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 года назад +1

      It would have to be
      object[item][prop]

    • @AE-yr6mo
      @AE-yr6mo 4 года назад

      @@SteveGriffith-Prof3ssorSt3v3 Hmm ok, what's the reason for that?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 года назад +1

      @@AE-yr6mo the item variable is just the name of the item1 or item2 property, not the actual property

  • @mariero1080
    @mariero1080 6 лет назад

    Thanks bro this video was really helpful, I really appreciate it

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

    than you , it was very helpful.

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

    This guy is the Bob Ross of coding.

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

    thanks so much!

  • @yuriisabodakh6182
    @yuriisabodakh6182 5 лет назад

    Thanks a lot!

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

    Thanks

  • @GabrielMartinez-ez9ue
    @GabrielMartinez-ez9ue 5 лет назад

    Finally! THANKS MAN

  • @fahadhafeez8086
    @fahadhafeez8086 5 лет назад

    Perfection!

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

    thanks!

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

    Is a for...in loop the same as a for...of loop?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 года назад +1

      No there are not. They are similar in what they do but different in how. ruclips.net/video/wc4jMuumqLM/видео.html
      ruclips.net/video/OC9D9REnXPw/видео.html
      ruclips.net/video/unDSLi5zBXU/видео.html

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

    Awesome!
    PS: You sound like jerry rig

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

    This is 2021 and I just learn how to use for in for a video from 2016, internet is awesome, is just not as awesome as u Steve haha

  • @webb-developer
    @webb-developer Год назад

  •  4 года назад

    you should open an online boot camp! for real!

  • @DmitriyMalayevProfile
    @DmitriyMalayevProfile 5 лет назад

    Just tried it this way, it also works, awesome. Thanks Steve. Expect a gift card when I get a job. :)
    console.log(`In, ${properties}, we have the, ${monsters[properties]}`)

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

    So how can I know the length of the object? I want the number of items! The main question wasn't answered!!!
    Just kidding! If someone is actually wondering how to get the length you can use the Object.keys()
    Object.keys(monsters).length

  • @بتاعكمبيوتر
    @بتاعكمبيوتر 4 года назад

    u have to speak louder

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 года назад +1

      The videos that I made years ago were made with a cheap mic. Anything made in the last couple years has good quality audio.