JSFiddle - React, Tailwind, and code Playground
HTML
<span id="value">BILL.Municipal</span>
<p>Array: <span id="Array201603Concentration"></span></p>
<p>Array Sum: <span id="Array201603ConcentrationSum"></span></p>
JavaScript
const walk = (root, filter) => {
const result = [];
const follow = (root) => {
if (root instanceof Array) {
root.forEach(elem => {
follow(elem);
});
} else if (root instanceof Object) {
Object.keys(root).forEach(elem => {
if (elem === filter) {
result.push(root[elem]);
} else {
follow(root[elem]);
}
});
}
};
follow(root);
return result;
};
const tree = {
"BILL" : {
"Municipal" : {
"CAD" : {
"Short" : {
"Low" : {
"High" : {
"N" : {
"CANADA" : {
"IssueName00085" : {
"CA6832Z57Z70" : {
"201603" : {
"Concentration" : 2,
"ConcentrationTier1" : 2,
"ConcentrationTier2" : 0,
"LargestTicket" : 0,
"Maturity" : 201708,
"Outstanding" : 140,
"SmallestTicket" : 0,
"Turnover" : 0,
"TurnoverTeir2" : 0,
"TurnoverTier1" : 0
},
"201604" : {
"Concentration" : 6,
"ConcentrationTier1" : 3,
"ConcentrationTier2" : 3,
"LargestTicket" : 0,
"Maturity" : 201708,
"Outstanding" : 140,
"SmallestTicket" : 0,
"Turnover" : 0,
"TurnoverTeir2" : 0,
"TurnoverTier1" : 0
}
}
}
},
"USA" : {
"IssueName00953" : {
"USA688I57Z70" : {
"201603" : {
"Concentration" : 4,
"ConcentrationTier1" : 2,
...