I want to show some data depending on which month it is. I have an array from 0 to 11. I'm confused on how to do this because there are multiple arrays inside of the object and it's scaring me lol
[
{
l: false,
u: 'AU',
n: 'Adelaide',
rain: [
22.4091,
18,
26.0909,
42.875,
56.9205,
68.0568,
75.4205,
66.3636,
58.8977,
48.75,
28.2159,
27.9545,
],
},
{
l: false,
u: 'AU',
n: 'A Different Place',
rain: [
22.4091,
18,
26.0909,
42.875,
56.9205,
68.0568,
75.4205,
66.3636,
58.8977,
48.75,
28.2159,
27.9545,
],
},
];
I have a variable that I can reference like this: getMonth(new Date(this.props.startDate))
0
Can I do something like this?
forEach(data[x].rain[getMonth(new Date(this.props.startDate))])
I'd like to replace the existing rain array with the data of the corresponding month. So for example if it was January (0) I'd like data[1].rain = 22.4091
expected output if (getMonth = 0):
[
{
l: false,
u: 'AU',
n: 'Adelaide',
rain: 22.4091
},
{
l: false,
u: 'AU',
n: 'A Different Place',
rain: 22.4091
],
},
];