Attempting to build an array, which outputs data as following:
Healthcare
-- Data-driven insights to improve healthcare
-- Urban AnalyticsTransport
-- Urban AnalyticsCities
-- Urban Analytics
I've tried looping 'expertise'/'text' but I'm unable to get them to work together to get the desired output within the console.log
Any and all help would be highly appreciated.
var items = [{
"item": {
"id": 0,
"sector": 'Data',
"expertise": ["Healthcare"],
"text": "Data-driven insights to improve healthcare"
}
},
{
"item": {
"id": 1,
"sector": 'Data',
"expertise": ["Healthcare", "Transport", "Cities"],
"text": "Urban Analytics"
}
}
}];
var array = [];
for (var i = 0; i < items.length; i++) {
var arr = [{
'title': items[i].item.sector,
'items': []
}];
for (var j = 0, b = items[i].item.expertise.length; j < b; j++) {
if (items[i].item.expertise[j] == expertise) {
arr[0]['items'].push({
'list': items[i].item.text
});
}
}
array.push(arr);
}
console.log(array);