/ 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.
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.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
var obj = JSON.parse('{"someKey":10,"otherKey":20}') ; for(var prop in obj) { if(obj.hasOwnProperty(prop)) console.info(obj[prop]); // value console.info(prop); // key name }