Posted By

iroybot on 02/09/11


js object array key name Value dynamic json

Versions (?)

Who likes this?

1 person have marked this snippet as a favorite


getting an objects key values

 / Published in: JavaScript


I wanted to pass a form submission (array) as a JSON object to another function. Some form field were created with JS, to identify them their names have been concatenated with unique IDs, etc. In order to access values of that JSON obj I needed to find out the key names in order to get data out of it.

  1. var obj = JSON.parse('{"someKey":10,"otherKey":20}') ;
  3. for(var prop in obj) {
  4. if(obj.hasOwnProperty(prop))
  5.[prop]); // value
  6.; // key name
  7. }

Report this snippet  

You need to login to post a comment.