-3

I am trying to get the status of de.zip-code but get a error Cannot read property 'status' of undefined. In my js file I have this

$.getJSON("link", function(json) { let creditcheck = json.de_zip_code.status; and more.

{
de.zip-code: {
   status: "RED",
   link: "link",
   text: "text"
},
glasvezel-availability: {
   status: "RED",
   link: "link",
   text: "text"
}
}

1 Answers1

-1

You have to use the same name as your property when trying to access it (creditcheck = json.de_zip_code.status won't work).

If that property contains special characters (. and - here), then you must use the bracket notation instead of dot notation to access the property:

data['de.zip-code'].status

See the doc about property accessors.

const data = {
  'de.zip-code': {
     status: 'RED',
     link: 'link',
     text: 'text'
  },
  'glasvezel-availability': {
     status: 'RED',
     link: 'link',
     text: 'text'
  }
};

console.log(data['de.zip-code'].status);
jo_va
  • 13,504
  • 3
  • 23
  • 47