user2783193 user2783193 - 5 months ago 19
AngularJS Question

manipulating json data and simple for statement

If I'm getting some data as an array

var data = {"answer":"OK","data":[["Marco","123"],["John","44245"],["Wayne","645464"]]}


how can I inside loop iterate trough them and print inside console this coresponding values

Marco 123
John 44254, ..

Marco - 123
John - 44245, ...
for (var i = 0; i < data.length; i++) {

}

Answer

data is a key of data object.You need to first retrieve the value of data.data which will return an array. Now loop through each of these array elements to get the values.

var data =  {"answer":"OK",
        "data":[["Marco","123"],["John","44245"],["Wayne","645464"]]
        }

var getData = data.data; //data key is an array

getData.forEach(function(item){
      item.forEach(function(innerItem){
       console.log(innerItem)
   })
})

JSFIDDLE