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!
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!
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.
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...
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.
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.
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.
@@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
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.
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] ); }
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.
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.💡
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?
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
[ { 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 ?
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!
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.
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!
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
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
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]}`)
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
best "for in loops" video so far. Cleared up confusions i had from watching other tutorials.
I am a new Dev and this video was the most helpful I've seen, thank you!
This is by far the best and simplest explanation of this concept. THANK YOU
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!
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!
over 30 minutes of looking for an anwser. Thank you, Sir.
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!
I was having a hard time wrapping my head around the concept, but you made it so easy! THANK YOU SO MUCH!
Wow! This was extremely helpful. I love your teaching style and pace--just perfect. Thank you very much!
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.
I wonder why not so many watching this. This is excellent. Thanks
Your channel is a hidden gem man
Subscribed after just watching this video. You gave a very clear explanation on the for...in loop in just 7 mins! Thank you!!!
you make it easy to understand and have a very soothing voice! thank you
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...
Yet another awesome tutorial! Cheers!
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.
Awesome tutorials.. You are helping me a lot. Thanks
Thank you for this. You have a real calm way of explaining this. Much appreciated.
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?
Brilliant video - thanks for explaining the for in loop really simply!
Thank you for your explanation for monster [prop]. I dont really understand the use for the bracket before and now i do.
Haven't watched it yet but I gotta pay homage to the Sensei.
At this rate, Imma owe you royalties when I get hired
Great job sir, it is very clear to understand the way you explain it .
Thank You Steve, I have better understanding after watching your video...
This playlist is golden
this is great, thank you. i was recommended to your channel by a random youtuber :-)
Your explanation is just awesome...
Brilliant tutorials !!!
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.
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.
@@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
Nice explanation sir
Thank you! This is a great explanation, I could easily understand everything
clear as crystal, You Are AMAZING Thats For Sure
Thank you for such a beautiful explanation!
Despite is for 2016 this is very helpful in 2019, thanks for taking the time to explain
2022...lol
Thank you very much!! This cleared out so much ambiguity for me. Makes perfects sense now!! You are Zbest!!
very clear and simple. Thanks!
Very informative! Thank you.
Thank you! This specifically was hard to understand just from documentation
You just saved me from losing my mind lol!! Thanks for the great help👍
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.
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] );
}
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.
const can be used but really makes no difference.
@@SteveGriffith-Prof3ssorSt3v3 yeah it's matter of preference.
Any chance you have a beginner playlist of more videos like this? You explained it better than the premium courses I'm paying for.
Thanks. Yes I have a playlist called Javascript from the start.
How are these not the most popular code videos on the YT?
5:40 , best explaination
so helpful! you are the best!
Thanks you for information
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.💡
Ty from Brazil.
best of the best thanks professor👌♥ it'll be even better if you could teach for...of loops too thanks again
ruclips.net/video/wc4jMuumqLM/видео.html
and the playlist for loops:
ruclips.net/video/CidzYW-8I7s/видео.html
Thank you very much, great explanation!
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?
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
Yep, very clear!
no formation without repetition, second round makes me feel better. Thank you.
Thanks for making this dude
thank you Lord Steve .
[
{ 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 ?
props[pets].name ... i have got it thanks a lot sir
Love the sound in the end, boom, boom, boom :D
Thanks dude. You help me a lot to understand this :)
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!
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.
@@SteveGriffith-Prof3ssorSt3v3 when the objects are nested inside an array, do they have the length property then?
@@harrietiluekhabho9795 objects don't have a length property
very very helpful tutorial
thank you for this video!
Thanks bro😘
Thank You Sir
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!
Prop is just a variable. You can call it whatever you like.
Merci beaucoup !!!!
are they still usable after es6? is there a way to do it with modern array methods?
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.
How would one log a single value within an object? Say you only wanted to console log the "Nepal : 'Yeti'" property.
console.log( monsters.Nepal );
Thank you 🙂
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
It would have to be
object[item][prop]
@@SteveGriffith-Prof3ssorSt3v3 Hmm ok, what's the reason for that?
@@AE-yr6mo the item variable is just the name of the item1 or item2 property, not the actual property
Thanks bro this video was really helpful, I really appreciate it
than you , it was very helpful.
This guy is the Bob Ross of coding.
thanks so much!
Thanks a lot!
Thanks
Finally! THANKS MAN
Perfection!
thanks!
Is a for...in loop the same as a for...of loop?
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
Awesome!
PS: You sound like jerry rig
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
☑
you should open an online boot camp! for real!
If only I had time.
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]}`)
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
u have to speak louder
The videos that I made years ago were made with a cheap mic. Anything made in the last couple years has good quality audio.