var xiaoming = {
name: 'Ming'.birth: 1990.school: 'No.1 Middle School'.height: 1.70.weight: 65.score: null
};
for(var i in xiaoming){
console.log(`${i}:${xiaoming[i]}`);
}
// The output will be normalName: xiao Ming birth:1990
school:No1. Middle School
height:1.7
weight:65
score:nullIf it isfor(var i in xiaoming){
console.log(`${i}:${xiaoming.i}`);
}
// The output is
name:undefined
birth:undefined
school:undefined
height:undefined
weight:undefined
score:undefined
Copy the code
This result is due to the fact that the preceding I normally iterates through the object’s property name and prints it. The following xiaoming. I is actually the I property of the object called xiaoming, so undefined is output.
If you add I to a variable, you’ll see that the output will print the value of the I property seven times.