Olaitan Adeboye
Olaitan Adeboye

Reputation: 172

Loop through JSON in ionic

Is there a way to loop through a JSON like below in ionic 3

[
 {
   "date": "28/09/2017 08:03",
   "data": {
     "1": 10,
     "2": 0
   }
},
{
   "date": "28/09/2017 08:04",
   "data": {
    "1": 0,
    "2": 5
   }
}
]

I have tried to loop through but to no avail. This is the latest i have tried but not working

this.data = returnedJson;

  for (let reportData of this.data.data) {
        console.log("Our Data : " + reportData);
    }

and

  for (let reportData in this.data.data) {
        console.log("Our Data : " + reportData);
    }

Upvotes: 1

Views: 2063

Answers (1)

Marcelo Cantos
Marcelo Cantos

Reputation: 185842

Try this:

for (const item of this.data) {
    console.log("Our Data : " + item.data);
}

Upvotes: 1

Related Questions