Struggling to create an array that will display data in the following format:
Healthcare
-- Insights driven by data for improved healthcare
-- Urban AnalyticsTransport
-- Urban AnalyticsCities
-- Urban Analytics
I have attempted to iterate over 'expertise' and 'text', but I am having difficulty getting them to work together to achieve the desired output within console.log
Any assistance or guidance would be greatly appreciated.
var items = [{
"item": {
"id": 0,
"sector": 'Data',
"expertise": ["Healthcare"],
"text": "Insights driven by data for improved 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);