本文翻译自:How to access the first property of an object in Javascript?
Is there an elegant way to access the first property of an object... 是否有一种优雅的方式来访问对象的第一个属性...
- where you don't know the name of your properties 你不知道你的房产名称的地方
- without using a loop like
for .. in
or jQuery's$.each
不使用像for .. in
或者jQuery的$.each
For example, I need to access foo1
object without knowing the name of foo1: 例如,我需要在不知道foo1名称的情况下访问foo1
对象:
var example = {
foo1: { /* stuff1 */},
foo2: { /* stuff2 */},
foo3: { /* stuff3 */}
};
#1楼
参考: