Jaydeep Gondaliya Jaydeep Gondaliya - 1 year ago 141
jQuery Question

Get jsondata value in javascript


var jsondata={"id": "10", "skills": "english", "post": "devloper", "emp_name": "jaydeep","timestemp":"10:45"}

I am trying to get each element key and value:



Expected Output :

emp_name = jaydeep

post = devloper

I am getting undefined in console. WHY? I tried data.post, i tried loop but no success..

Answer Source

You can use basic JS too to attain this.

// property is an optional parameter
function disp(obj, property) {
  var prop;
  if (property) {
    obj[property] && (console.log(obj[property]));
  } else {
    for (prop in obj) {
      console.log(prop + " = " + obj[prop])
var jsondata = {
  "id": "10",
  "skills": "english",
  "post": "devloper",
  "emp_name": "jaydeep",
  "timestemp": "10:45"

//disp(jsondata, "post");

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download