javascript “for (x in y)”声明
//just copied this code from w3schools
var person={fname:"John",lname:"Doe",age:25};
for (x in person)
{
document.write(person[x] + " ");
}
我想知道,我必须假设什么而不是“x”。
//just copied this code from w3schools
var person={fname:"John",lname:"Doe",age:25};
for (x in person)
{
document.write(person[x] + " ");
}
I want to know that, what I have to assume instead of "x".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您希望
这将为您提供键列表而不是值列表。
You want to have
this will give you a list of KEYS rather than a list of values.
person
是对象,X
是在for
循环迭代中使用的变量,您可以将其命名为除X
X也:)。这里X
作为对象的key
,例如:这里
fname
与其他键一起存储在X
中作为lname
和age
。The
person
is object andX
is variable used in iteration of thefor
loop, you can name it anything other thanX
also :). HereX
works askey
of the object for example:Here
fname
is stored inX
along with other keys such aslname
andage
.