JSFiddle - React, Tailwind, and code Playground
JavaScript
var jsonObject = [
[
{
"count": "80",
"countTxt":"Buyer logins",
"participantsTxt":"Total for all participating member companies:",
"participantCount":"523"
},
{
"count": "233",
"countTxt":"Searches",
"participantsTxt":"Total for all participating member companies:",
"participantCount":"628"
},
{
"count": "533",
"countTxt":"Views of our member pages",
"participantsTxt":"Total for all participating member companies:",
"participantCount":"2,365"
}
],
[
{
"count": "80",
"countTxt":"Total vists",
"participantsTxt":"Total for all participating member companies:",
"participantCount":"412"
},
{
"count": "53",
"countTxt":"Unique visitors",
"participantsTxt":"Total for all participating member companies:",
"participantCount":"731"
},
{
"count": "1:12 min",
"countTxt":"Total time spent on page",
"participantsTxt":"Total for all participating member companies:",
"participantCount":"784.2 mins"
}
]
];
// List off all "countTxt" objects to demonstrate how to
// iterate over a json object that contains nested
// arrays containing data. In your example, you have two arrays
// that each contain json data.
for (var i in jsonObject) {
for (var j in jsonObject[i]){
console.log(jsonObject[i][j].countTxt);
}
}
// the above loop will print out the following:
/*
Unique visitors
Total time spent on page
Buyer logins
Searches
Views of our member pages
Total vists
Unique visitors
Total time spent on page
*/
// If you want to target a specific item in the jsonObject, you do // so like this:
// Grab the second object in the data array:
var secondObjectInJsonData = jsonObject[1];
console.log(secondObjectInJsonData);
// secondObjectInJsonData -> [Object,...