I have two arrays. One contains a series of dates. The other array contains a series of data. What is the best way to combine the two arrays into one array of objects.
As an example the first element of the first array will be in the same object as the first element in the second array.
HERE ARE THE TWO ARRAYS
const datesArray = [
"2017-01-01",
"2017-01-02",
"2017-01-03",
"2017-01-04",
"2017-01-05",
"2017-01-06",
"2017-01-07",
"2017-01-08",
"2017-01-09",
"2017-01-10",
"2017-01-11",
"2017-01-12",
"2017-01-13",
"2017-01-14",
"2017-01-15",
"2017-01-16",
"2017-01-17",
"2017-01-18",
"2017-01-19",
"2017-01-20",
"2017-01-21",
"2017-01-22",
"2017-01-23",
"2017-01-24",
"2017-01-25",
"2017-01-26",
"2017-01-27",
"2017-01-28",
"2017-01-29",
"2017-01-30",
"2017-01-31",
];
const snowfallArray = [
0.98, 0, 0, 0, 0, 0, 0.35, 0.42, 0, 0.14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
];
HERE IS MY EXPECTED OUTPUT
let combinedArray = [{
date: *first element from dates array*,
snowFall: *first element from snowfall array*
},
{
date: *second element from dates array*,
snowFall: *second element from snowfall array*
}]
EXPECTED OUTPUT EX: let combinedArray = [{date: '2017-01-01', snowFall: 0.98},{date: '2017-01-02', snowFall: 0}]
I do not even know where to begin..