I need to parse json api response, with response.data equals:
[
{
"name": "Programming",
"subcategories": [
{"name": "web-development"},
{"name": "backend-development"},
{"name": "data-scince"}
]
},{
"name": "Design",
"subcategories": [
{"name": "Graphic-design"},
{"name": "Motion-design"},
{"name": "3D modeling"}
]
and I need to return one array[String] with all subcategories, ex ["web-development", "backend-development" ... "3D modeling"]
All that I did is:
let subs = categories.data.map(function(category) {
return category.subcategories.map(function(subcategory) {
return subcategory.name
})
})
and it returns Array of arrays with categories. Im sure, that there near a better and easier way. Thanks!
responsethe same thing ascategories? NB: the fact that this array comes from an API response seams irrelevant to your question.