var data=[{
"name": "cA",
"leaf": false,
"largeIconId": null,
"label": "cA",
"hideAllSearchFilters": false,
"guidePage": null,
"expanded": false,
"defaultSearchCategory": false,
"childCategories": [{
"name": "cA-A",
"leaf": false,
"largeIconId": null,
"label": "cA-A",
"hideAllSearchFilters": false,
"guidePage": null,
"expanded": false,
"defaultSearchCategory": false,
"childCategories": [{
"name": "cA-A-A",
"leaf": false,
"largeIconId": null,
"label": "cA-A-A",
"hideAllSearchFilters": false,
"guidePage": null,
"expanded": false,
"defaultSearchCategory": false,
"childCategories": [{
"name": "cA-A-A-A",
"leaf": false,
"largeIconId": null,
"label": "cA-A-A-A",
"hideAllSearchFilters": false,
"guidePage": null,
"expanded": false,
"defaultSearchCategory": false,
"childCategories": [{
"name": "cA-A-A-A-A",
"leaf": true,
"largeIconId": null,
"label": "cA-A-A-A-A",
"hideAllSearchFilters": false,
"guidePage": null,
"expanded": false,
"defaultSearchCategory": false,
"childCategories": []
}]
}]
}]
}, {
"name": "cA-B",
"leaf": true,
"largeIconId": null,
"label": "cA-B",
"hideAllSearchFilters": false,
"guidePage": null,
"expanded": false,
"defaultSearchCategory": false,
"childCategories": []
}, {
"name": "cA-C",
"leaf": true,
"largeIconId": null,
"label": "cA-C",
"hideAllSearchFilters": false,
"guidePage": null,
"expanded": false,
"defaultSearchCategory": false,
"childCategories": []
}]
}, {
"name": "A",
"leaf": false,
"largeIconId": null,
"label": "A",
"hideAllSearchFilters": false,
"guidePage": null,
"expanded": false,
"defaultSearchCategory": false,
"childCategories": [{
"name": "A-Level1",
"leaf": false,
"largeIconId": null,
"label": "A-Level1",
"hideAllSearchFilters": false,
"guidePage": null,
"expanded": false,
"defaultSearchCategory": false,
"childCategories": [{
"name": "A-Level2",
"leaf": true,
"largeIconId": null,
"label": "A-Level2",
"hideAllSearchFilters": false,
"guidePage": null,
"expanded": false,
"defaultSearchCategory": false,
"childCategories": []
}]
}]
}];
Asked
Active
Viewed 73 times
-3

Jagdish Idhate
- 7,513
- 9
- 35
- 51

Srikanth Pullela
- 241
- 1
- 12
-
1So do that. If you run into a *specific* problem with it, post a new question with A) A clear explanation of what you want, including the desired result; and B) Your code attempting to produce that result from the input. – T.J. Crowder Apr 20 '16 at 08:26
-
1Separately: When you were asking your question, there was a big orange **How to Format** box to the right of the text area with useful information in it. There was also an entire toolbar of formatting aids. And a **[?]** button giving formatting help. *And* a preview area located between the text area and the Post Your Question button (so that you'd have to scan past it to find the button) showing what your post would look like when posted. Making your post clear, and demonstrating that you took the time to do so, improves your chances of getting good answers. – T.J. Crowder Apr 20 '16 at 08:28
1 Answers
1
This is a proposal in Vanilla.js with Array#forEach()
in a recursive fashion.
function getNames(a) {
this.push(a.name);
Array.isArray(a.childCategories) && a.childCategories.forEach(getNames, this);
}
var data = [{ "name": "cA", "leaf": false, "largeIconId": null, "label": "cA", "hideAllSearchFilters": false, "guidePage": null, "expanded": false, "defaultSearchCategory": false, "childCategories": [{ "name": "cA-A", "leaf": false, "largeIconId": null, "label": "cA-A", "hideAllSearchFilters": false, "guidePage": null, "expanded": false, "defaultSearchCategory": false, "childCategories": [{ "name": "cA-A-A", "leaf": false, "largeIconId": null, "label": "cA-A-A", "hideAllSearchFilters": false, "guidePage": null, "expanded": false, "defaultSearchCategory": false, "childCategories": [{ "name": "cA-A-A-A", "leaf": false, "largeIconId": null, "label": "cA-A-A-A", "hideAllSearchFilters": false, "guidePage": null, "expanded": false, "defaultSearchCategory": false, "childCategories": [{ "name": "cA-A-A-A-A", "leaf": true, "largeIconId": null, "label": "cA-A-A-A-A", "hideAllSearchFilters": false, "guidePage": null, "expanded": false, "defaultSearchCategory": false, "childCategories": [] }] }] }] }, { "name": "cA-B", "leaf": true, "largeIconId": null, "label": "cA-B", "hideAllSearchFilters": false, "guidePage": null, "expanded": false, "defaultSearchCategory": false, "childCategories": [] }, { "name": "cA-C", "leaf": true, "largeIconId": null, "label": "cA-C", "hideAllSearchFilters": false, "guidePage": null, "expanded": false, "defaultSearchCategory": false, "childCategories": [] }] }, { "name": "A", "leaf": false, "largeIconId": null, "label": "A", "hideAllSearchFilters": false, "guidePage": null, "expanded": false, "defaultSearchCategory": false, "childCategories": [{ "name": "A-Level1", "leaf": false, "largeIconId": null, "label": "A-Level1", "hideAllSearchFilters": false, "guidePage": null, "expanded": false, "defaultSearchCategory": false, "childCategories": [{ "name": "A-Level2", "leaf": true, "largeIconId": null, "label": "A-Level2", "hideAllSearchFilters": false, "guidePage": null, "expanded": false, "defaultSearchCategory": false, "childCategories": [] }] }] }],
names = [];
data.forEach(getNames, names);
document.write('<pre>' + JSON.stringify(names, 0, 4) + '</pre>');

Nina Scholz
- 376,160
- 25
- 347
- 392