1

I have a js object and i'm trying to access it directly without having to do something like :

for(i in data) { obj = data[i] }

is there a better way to access this object without looping ? (i'll always have 1 result)

here is the firebug result for console.log(data) :

enter image description here

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
commandos
  • 171
  • 1
  • 8

1 Answers1

2

No, you can't access a property without knowing its name (aside from using fancy for-of-loops). And to get that name, you only can enumerate the properties with a for-in-loop or use Object.keys/….getOwnPropertyNames.

If you know that you always have exactly one key in your object, you might have chosen the wrong data structure.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
  • in that specific case yes i get only 1 result because i'm using the same function that return all users . – commandos Jan 17 '13 at 17:09