I have seen questions about dealing with “nested json” in d3.js and have seen that the proposed solutions are mostly to “flatten” the data (meaning creating a new variable and pushing in the data in desired level) Here two examples:
My question is : can one use one of the various array functions to access the level of the data without creating a new variable ? Handling arrays
I have an array which looks like that:
var dataset =
{"directed": false,
"graph": [],
"nodes":
[
{"Region": "X15", "Group": "EU", "id": "BE"},
{"id": "FR"},
{"id": "BG"},
{"id": "DK"},
{"id": "HR"},
{"id": "DE"}
],
"links":
[
{"source": 0, "target": 0, "weight": 0},
{"source": 0, "target": 1, "weight": 130},
{"source": 0, "target": 2, "weight": 1},
{"source": 0, "target": 3, "weight": 36},
{"source": 0, "target": 4, "weight": 4},
{"source": 0, "target": 5, "weight": 117}
],
"multigraph": false}
I have tried the following
and Iwould like to access the weight (calculating its maximum with d3.max)
dataset.links // gives me link
dataset.links[0].weight // gives me the weight of first but can't get the index to work
when using the array functions I can't get elements lower than that
d3.entries(dataset)
d3.values(dataset.links)
what am I missing ?
I hope the question makes sense.
P.S: if one has to flatten the array, is there any advantage of doing it in javascript or is it the same if I create the array (e.g. in python) and pass it to javascript