Posted By

iroybot on 02/09/11


Tagged

js object array key name Value dynamic json


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

iroybot


getting an objects key values


 / Published in: JavaScript
 

URL: http://stackoverflow.com/questions/587881/how-to-iterate-over-every-property-of-an-object-in-javascript/588276#588276

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}') ;
  2.  
  3. for(var prop in obj) {
  4. if(obj.hasOwnProperty(prop))
  5. console.info(obj[prop]); // value
  6. console.info(prop); // key name
  7. }

Report this snippet  

You need to login to post a comment.