【发布时间】:2017-01-04 19:47:01
【问题描述】:
我有一个包含键值对的数组。
var array=[
{Key:"Name",Value:"Sam" },
{Key:"Marks",Value:"50"},
{Key:"Subject",Value:"English"},
];
我想将Key 为“主题”的对象的Value 推送到变量中。我试图查看如何访问 Value,但在第一步就失败了。
如何才能做到这一点?
for (var key in array[0])
{
console.log(key[i].Value); //error: Cannot read property 'Value' of undefined
}
如何将Key 为“主题”的对象的Value 推送到变量中?
【问题讨论】:
-
@AmitKumarGhosh:请考虑更高质量的参考网站,例如MDN。
-
是的。你是对的。 @T.J.