getting an objects key values

/ Published in: JavaScript
Save to your folder(s)

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.

Copy this code and paste it in your HTML
  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


RSS Icon Subscribe to comments

You need to login to post a comment.