Transcript for:
Understanding JavaScript `for...in` Loop

so today we will use the for in loop the for in loop in JavaScript is used to iterate over the innumerable properties of an object it allows you to look through all the keys or properties of an object making it useful when you want to access each property name and its corresponding value let's see how to use the for in Loop we have a developer object with some keys and values to use for in Loop we can add the for keyword and inside the parenthesis we can add let key in developer here key means the property name and developer means the object name now to log all property names in the console we can use console.log key it will then return all key names like name age and City likewise to log all the property values we can use the same for in Loop but in the console we have to use the bracket notation so add developer and inside square bracket we need to pass a key variable now this will return property values like Amy 27 and London now let's check them in action in my script.js I have a developer object just after this object let's add a for in Loop so I will add the for keyword inside the parentheses I will add let key in developer now let's log the key in the console so I will use console.log key if you check the preview we can see all the key or property names like name age and city now let's try to show the property values as well so let me remove this key and instead I will add a back tick inside I will add $key colon and there is one thing you should remember we cannot use dot notation to show the property value if we use $developer.key it shows undefined so we should always use the square bracket notation so instead of a dot I will add a key inside a square bracket if you check the preview again this time it works as expected great this is the end of this session in the next session will store objects in an array feel free to comment below if you have any questions also please don't forget to like share and subscribe to my channel to get more videos in the future thank you and see you soon