I have two arrays and I need to create objects like {x: new Date(2019, 1, 1), y: 0} The result of my arrays looks like this
dates
Array [
"2019, 1, 31",
"2019, 2, 28",
"2019, 3, 31",
]
monthlyTopUp
Array [
0,
50,
0,
]
Now each index from first array needs to match the index from second array.
What I've tried returned me an array with other arrays inside
Array [
Array [
"2019, 1, 31",
0,
],
Array [
"2019, 2, 28",
50,
],
Array [
"2019, 3, 31",
0,
],
]
The way I've done this:
const array = [dates, monthlyTopUp];
const data = array.reduce(
(dates, topUp) => topUp.map((v, i) => (dates[i] || []).concat(v)), []
);
console.log(data)
{x: new Date(2019, 1, 1), y: 0}