Another common type of loop in JavaScript is the for..in loop. When working with Arrays the for loop is the most common type of loop. When working with Objects, the for..in loop is usually the best choice.
Пікірлер: 109
@zooneyl22482 жыл бұрын
best "for in loops" video so far. Cleared up confusions i had from watching other tutorials.
@MasterZiomekPL5 жыл бұрын
over 30 minutes of looking for an anwser. Thank you, Sir.
@johnaldrineilao Жыл бұрын
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!
@ShotgunMechanic4 жыл бұрын
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!
@ashleypean4 жыл бұрын
This is by far the best and simplest explanation of this concept. THANK YOU
@kira12492 жыл бұрын
Your channel is a hidden gem man
@envilove24434 жыл бұрын
I was having a hard time wrapping my head around the concept, but you made it so easy! THANK YOU SO MUCH!
@chantuff93772 жыл бұрын
I am a new Dev and this video was the most helpful I've seen, thank you!
@SharronV4 жыл бұрын
Wow! This was extremely helpful. I love your teaching style and pace--just perfect. Thank you very much!
@thecoder1631 Жыл бұрын
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.
@kubkato4 жыл бұрын
Subscribed after just watching this video. You gave a very clear explanation on the for...in loop in just 7 mins! Thank you!!!
@nnovell15024 жыл бұрын
I wonder why not so many watching this. This is excellent. Thanks
@IgnitWacom2 жыл бұрын
you make it easy to understand and have a very soothing voice! thank you
@thomascarlton822 жыл бұрын
Haven't watched it yet but I gotta pay homage to the Sensei. At this rate, Imma owe you royalties when I get hired
@logan11032 жыл бұрын
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!
@rotrose75314 жыл бұрын
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.
@jp-hz6br4 жыл бұрын
Brilliant video - thanks for explaining the for in loop really simply!
@silentgaming56023 жыл бұрын
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...
@ToddsDiscGolf2 жыл бұрын
this is great, thank you. i was recommended to your channel by a random youtuber :-)
@Pharizer3 жыл бұрын
Yet another awesome tutorial! Cheers!
@nelsonjimenez79395 жыл бұрын
Awesome tutorials.. You are helping me a lot. Thanks
@itsmattcarr2 жыл бұрын
This totally made sense! Thank you so much!
@NeonLightification3 жыл бұрын
Thank you for this. You have a real calm way of explaining this. Much appreciated.
@NeonLightification3 жыл бұрын
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?
@aruppanda98005 жыл бұрын
Your explanation is just awesome...
@amyglaskin31244 жыл бұрын
Thank You Steve, I have better understanding after watching your video...
@qatadd83133 жыл бұрын
clear as crystal, You Are AMAZING Thats For Sure
@ChrisTian-ox5nr4 жыл бұрын
Thank you very much!! This cleared out so much ambiguity for me. Makes perfects sense now!! You are Zbest!!
@chesterxp5082 жыл бұрын
Brilliant tutorials !!!
@kaelenanderson84662 жыл бұрын
very clear and simple. Thanks!
@shalakakapure36832 жыл бұрын
Thank you for such a beautiful explanation!
@camilogarcia13254 жыл бұрын
Despite is for 2016 this is very helpful in 2019, thanks for taking the time to explain
@harrietiluekhabho97952 жыл бұрын
2022...lol
@tkells51094 жыл бұрын
You just saved me from losing my mind lol!! Thanks for the great help👍
@leiliang96602 жыл бұрын
so helpful! you are the best!
@atulraj894 жыл бұрын
Love the sound in the end, boom, boom, boom :D
@chiculitamihaela80762 жыл бұрын
Thank you! This is a great explanation, I could easily understand everything
@spikeadam66532 жыл бұрын
Very informative! Thank you.
@mnfak43333 жыл бұрын
Thank you for your explanation for monster [prop]. I dont really understand the use for the bracket before and now i do.
@alexandermurzin8834 жыл бұрын
Thank you very much, great explanation!
@pablo.dm32 жыл бұрын
Great job sir, it is very clear to understand the way you explain it .
@moderncloth6823 жыл бұрын
How are these not the most popular code videos on the YT?
@GabrielMartinez-ez9ue5 жыл бұрын
Finally! THANKS MAN
@assegidbelda39912 жыл бұрын
Nice explanation sir
@mariero10806 жыл бұрын
Thanks bro this video was really helpful, I really appreciate it
@TokyoDynamite2 жыл бұрын
Thanks for making this dude
@brankoblesicjr.57924 жыл бұрын
Thanks dude. You help me a lot to understand this :)
@fahadhafeez80865 жыл бұрын
Perfection!
@arlessonmoura89443 жыл бұрын
Ty from Brazil.
@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.💡
@libsterism97453 жыл бұрын
thank you for this video!
@tolfpeck Жыл бұрын
Thank you! This specifically was hard to understand just from documentation
@yuriisabodakh61824 жыл бұрын
Thanks a lot!
@princedube83324 жыл бұрын
Yep, very clear!
@Youssef-lv6wp3 жыл бұрын
Thanks you for information
@brucebergkamp3 жыл бұрын
thank you Lord Steve .
@ryantanjaya58545 жыл бұрын
very very helpful tutorial
@ryaaan07512 жыл бұрын
thanks so much!
@rotrose75314 жыл бұрын
no formation without repetition, second round makes me feel better. Thank you.
@Chaos67793 жыл бұрын
Any chance you have a beginner playlist of more videos like this? You explained it better than the premium courses I'm paying for.
@SteveGriffith-Prof3ssorSt3v33 жыл бұрын
Thanks. Yes I have a playlist called Javascript from the start.
@mosdev2091 Жыл бұрын
Merci beaucoup !!!!
@samahgad241 Жыл бұрын
than you , it was very helpful.
@teenytinytoons3 жыл бұрын
This guy is the Bob Ross of coding.
@iamdanyaal2 жыл бұрын
Thank You Sir
@Aditya-xz5qv3 жыл бұрын
Thank you 🙂
@iiinicky62242 жыл бұрын
thanks!
@yasith63702 жыл бұрын
Thanks bro😘
@meowthemmd10 ай бұрын
best of the best thanks professor👌♥ it'll be even better if you could teach for...of loops too thanks again
@SteveGriffith-Prof3ssorSt3v310 ай бұрын
kzbin.info/www/bejne/rZSXm4CrqtKkgq8 and the playlist for loops: kzbin.info/www/bejne/eZrHq4yNYp18bdU
@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.
@SteveGriffith-Prof3ssorSt3v3 Жыл бұрын
const can be used but really makes no difference.
@pooyaestakhry Жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 yeah it's matter of preference.
@neoTriny3 жыл бұрын
5:40 , best explaination
@dyracho66672 жыл бұрын
Thanks
@AE-yr6mo3 жыл бұрын
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-Prof3ssorSt3v33 жыл бұрын
It would have to be object[item][prop]
@AE-yr6mo3 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 Hmm ok, what's the reason for that?
@SteveGriffith-Prof3ssorSt3v33 жыл бұрын
@@AE-yr6mo the item variable is just the name of the item1 or item2 property, not the actual property
@davyjones67783 жыл бұрын
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-Prof3ssorSt3v33 жыл бұрын
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] ); }
@MiguelMartinez-hm9wk5 жыл бұрын
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!
@SteveGriffith-Prof3ssorSt3v35 жыл бұрын
Prop is just a variable. You can call it whatever you like.
@zdarofMERGAITES4 жыл бұрын
are they still usable after es6? is there a way to do it with modern array methods?
@SteveGriffith-Prof3ssorSt3v34 жыл бұрын
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.
@xeniamelnik57523 жыл бұрын
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-Prof3ssorSt3v33 жыл бұрын
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.
@harrietiluekhabho97952 жыл бұрын
@@SteveGriffith-Prof3ssorSt3v3 when the objects are nested inside an array, do they have the length property then?
@SteveGriffith-Prof3ssorSt3v32 жыл бұрын
@@harrietiluekhabho9795 objects don't have a length property
@pranavks61604 жыл бұрын
Awesome! PS: You sound like jerry rig
@alishettima97882 жыл бұрын
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-Prof3ssorSt3v32 жыл бұрын
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 - kzbin.info/www/bejne/fovNp6Kcqbepfac
@johnywhy46794 жыл бұрын
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-Prof3ssorSt3v34 жыл бұрын
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.
@johnywhy46794 жыл бұрын
@@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
@ryanbooth39763 жыл бұрын
How would one log a single value within an object? Say you only wanted to console log the "Nepal : 'Yeti'" property.
@SteveGriffith-Prof3ssorSt3v33 жыл бұрын
console.log( monsters.Nepal );
@rodrigoluizrech80073 жыл бұрын
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
@faizanansari9753 жыл бұрын
[ { 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 ?
@faizanansari9753 жыл бұрын
props[pets].name ... i have got it thanks a lot sir
@webb-developer6 ай бұрын
☑
3 жыл бұрын
you should open an online boot camp! for real!
@SteveGriffith-Prof3ssorSt3v33 жыл бұрын
If only I had time.
@DmitriyMalayevProfile4 жыл бұрын
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]}`)
@NehemiahBradyP3 жыл бұрын
Is a for...in loop the same as a for...of loop?
@SteveGriffith-Prof3ssorSt3v33 жыл бұрын
No there are not. They are similar in what they do but different in how. kzbin.info/www/bejne/rZSXm4CrqtKkgq8 kzbin.info/www/bejne/hXScdWyIetOLhtk kzbin.info/www/bejne/q5-nhH-fat91jrc
@husseinalmosawi20014 жыл бұрын
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
@user-kn8th1vt2y4 жыл бұрын
u have to speak louder
@SteveGriffith-Prof3ssorSt3v34 жыл бұрын
The videos that I made years ago were made with a cheap mic. Anything made in the last couple years has good quality audio.