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
  • 837,282
  • 173
  • 1,862
  • 1,933
commandos
  • 181
  • 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
  • 572,313
  • 128
  • 898
  • 1,281
  • 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