sse sse - 1 year ago 104
Javascript Question

Extracting data from JSON returned undefined

I'm new to javascript and JSON. I have JSON like this:

data = [[{"checked":false,"no":"1"},{"checked":true,"no":"2"}]]

But I am having a hard time looping through just to get the "checked" value.

I used for loop then i try to console.log data.checked but it always returned undefined. How can do this?

Answer Source

Get first array element using index and use Array#forEach method for iterating.

var data = [
    "checked": false,
    "no": "1"
  }, {
    "checked": true,
    "no": "2"

data[0].forEach(function(v) {

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