[英]Get value from object without knowing the key
I have item.124bn1353v = 'foo'
我有
item.124bn1353v = 'foo'
However the 124bn1353v
key is dynamically generated but I need to get its value foo
. 但是,
124bn1353v
密钥是动态生成的,但是我需要获取其值foo
。 How can I get the foo
assuming that we have only one property in the item
? 假设
item
只有一个属性,如何获取foo
?
If there is only one property set on the item
object this will assign it to the variable foo
: 如果在
item
对象上仅设置了一个属性,则将其分配给变量foo
:
var foo;
for (var prop in item) {
if (item.hasOwnProperty(prop)) {
foo = item[prop];
}
}
Example JSFiddle - http://jsfiddle.net/VDyUe/ 示例JSFiddle- http://jsfiddle.net/VDyUe/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.