#21 For in loop in JavaScript

preview_player
Показать описание
Iterating over properties of an Object

More Learning :

Рекомендации по теме
Комментарии
Автор

Answer for 3:28, I have used in my coding with help of phones instead of laptop.

let alien = {
name : 'Chandramouli',
tech : 'Javascript',
phones : {
android_version : '11',
ram : '4',
brand1 : 'mi'
}
}
for(let key in alien.phones)
{
console.log(key, alien.phones[key]);
}

Output :
android_version 11
ram 4
brand1 mi

aravind
Автор

to get keys of laptop key :

for(let key in alien.laptop){
console.log(key)
}


to get values of laptop keys :

for(let key in alien.laptop){

}

//Alternative

 for(let key in alien["laptop"]){
        console.log(key)
    }

apoorv
Автор

At 3:28

let alien = {

name :'Adithya',
language: 'JS',
exp :'Fresher',
laptop : {

cpu : 'i3',
ram : '4',
brand : 'hp'

}

}
for (key in alien.laptop){
console.log(key, alien.laptop[key]);
}

adithya
Автор

for(let key in alien.laptop){
console.log(key, alien.laptop[key]);
}
I think it should work

sandeepprabhakula
Автор

Very nice series, Navin. I binge watched it in 2 hours it was so exciting ☺️ please keep it on. Waiting for the next one

mdirfanmullick
Автор

Oh why did i see this only now . Great teacher . Great sir

DesiVillagerEurope
Автор

The answer of 3.38 is:
For(let key in alien["laptop"]{
Console.log(key, alien.laptop[key])}

kheiromahiout
Автор

3:31 for( let key in alien){
if( typeof (alien[key]) === 'object') {
for(let key1 in alien[key]){
console.log(key1, alien[key][key1]);
}
}else
console.log(key, alien[key]);
}

lathavoggu
Автор

let Employee={
name:"Muskan",
age:22,
course:{
main_subjects:'Mathematics',
'minor subject':'English'}
};
for (let key in Employee.course){
console.log(key, Employee.course[key]);
}
output:-
main_subjects Mathemaics
minor subject English

muskangupta
Автор

Your teaching technique is really adorable...you made my day... 🤩 A million thanks to you ❤️🙏

deepalibiradar
Автор

Answer for 3:28 ||

for (key in alien.laptop)
{
console.log(key, alien.laptop[key])
}

shivampathak
Автор

3:30 -->
let alien = {
    name: "subham",
    tech: "JS",
    laptop: {
        cpu: "I7",
        RAM: 8,
        brand: "Asus",
    }
}


for(let key in alien.laptop)
{
    console.log(key, alien.laptop[key]);
}

subhrajitjana
Автор

thanks so much Navin, i am loving the series, i took your python course and i enjoyed it.
you know how to simplify everything to make it possible for us to learn. thank you so much

omatsoladev
Автор

@3:30 I used "p" instead of key.
The for in loop statement is;

for(let p in Alien.laptop){
console.log(p, Alien.laptop[p]);
}

batambuzestephen
Автор

I came back from the last video, here is my shortcut code: (it works even if the object has multiple objects in it):

function key_printer(obj, spaces = '')

{
for(keys in obj)
{
if(typeof obj[keys] != 'object')
{
console.log(spaces + keys);
}
else
{
console.log(spaces + keys);
key_printer(obj[keys], spaces + ' ')
}
}
}

key_printer(objects)

//Note: The word 'objects' is the object name. This works...

Excel-zuiv
Автор

to print the value of the object we can do this
for (const key in alien) {
if (Object.hasOwnProperty.call(alien, key)) {
const element = alien[key];
console.log(element);
}
}

maverick_
Автор

Answer for 3:28
Can be a bit overwhelming for beginners:

let alien = {
name: "Navin",
tech: "JS",
laptop:{
cpu: "i7",
ram: 4,
brand: "asus"

}

}


for(let key in alien){

switch(key){
case"laptop":
for(let key2 in alien["laptop"]){
console.log(key2, alien["laptop"][key2]);
}
default:
if(key === "laptop"){
break;
} else{
console.log(key, alien[key]);
}
}

}

sprinter
Автор

To print only laptop

for(let key in alien.laptop)
console.log(key, alien.laptop[key])

gbolahanalaba
Автор

3:40
//code for printing laptop keys along with their value
for(let key in alien.laptop){
console.log(key, alien.laptop[key])
}

hvardhan
Автор

The main thing I learnt from you was. Learn How to learn.😇

gowthammanikandan