0

i have object response from api in format

res = {
propid1:{data:resobj1},
propid2:{data:resobj2},
...
}
e.g.
res = {
2343434:{data:resobj},
67958:{data:resobj},
...
}

but propid1 is vary at run time, what is best way to access each data:resobj?

ps. propids is known(also vary) before api request like this

pid=[proid1,proid2,...]

thanks,

medici
  • 199
  • 1
  • 4
  • 11
  • You can use `for..in` and iterate `res`.. – choz Jan 02 '17 at 05:16
  • `for...in` loop over the properties or access using `Object.keys`? – Andrew Li Jan 02 '17 at 05:16
  • Here is the link - http://stackoverflow.com/questions/684672/how-do-i-loop-through-or-enumerate-a-javascript-object – ngrj Jan 02 '17 at 05:17
  • thanks, i'm new for javascript/typescript. at first, i try access with res.pid[i] and get error, now i change to res[pid[i]] and it work fine. don't know why but thanks anyway. – medici Jan 02 '17 at 12:29

0 Answers0