This post has been de-listed
It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.
2
Ways to access property values in a for...in statement
Post Body
let user = {
name: "John",
};
alert(user.name); //John
for (let key in user) alert(user.key); // undefined.
for(let key in user) alert(user[key]); //John
Outside the for..in loop using user.name is equal to "John". When i use this same notation in the for...in loop as user.key, wouldn't the key be replaced by name and become user.name and the alert would output "John".
However,this is not the case and the result is undefined instead of John. Can someone explain why this is not working?
Author
Account Strength
100%
Account Age
7 years
Verified Email
Yes
Verified Flair
No
Total Karma
52,382
Link Karma
17,058
Comment Karma
35,171
Profile updated: 14 hours ago
Posts updated: 8 months ago
Subreddit
Post Details
We try to extract some basic information from the post title. This is not
always successful or accurate, please use your best judgement and compare
these values to the post title and body for confirmation.
- Posted
- 3 years ago
- Reddit URL
- View post on reddit.com
- External URL
- reddit.com/r/learnjavasc...