Anyone help with extracting data from an array of objects.
{
"length":6792,
"data":[
{
"fruit":"Apples",
"id":32827,
"sales":[
{
"week":5,
"value":234
},
{
"week":6,
"value":278
},
{
"week":7,
"value":199
}
]
},
{
"fruit":"Pears",
"id":78736,
"sales":[
{
"week":5,
"value":178
},
{
"week":6,
"value":345
},
{
"week":7,
"value":286
}
]
}
]
}
I reality, there are many hundreds of objects in the array, and much more complex data in the objects, so the above is the example format.
I'd like to;
Select an object where fruit == Pears
(all of the names are unique - there's only 1 'Pears')
then be able assign a var to the sales
id, and finally use the sales
data to plot a chart.
I don't yet know the format of the chart, but if I can get 'sales', then I can sort the format later.
Basically, I'm wanting to just select & use one object, selected by the simple criteria fruit == Pears
.
I seem to remember that that there is a better way than iterating over the array... was it map
?
...but can't seem to work it out.
Thanks