I am trying to combine arrays of dates from firebase. I am retrieving the start date and end date on firebase and after that I have a method that gets all between the 2 dates.
firebase.database().ref("dummy_dates").once("value", snap => {
if (snap.val()) {
snap.forEach(snapShot => {
console.log('start date: ' + snapShot.val().startTime + "\nend date: " + snapShot.val().endTime)
this.enumerateDaysBetweenDates(snapShot.val().startTime, snapShot.val().endTime);
});
}
});
This method gets all the days between the 2 days I'm retrieving from firebase using the above firebase for loop:
enumerateDaysBetweenDates(startDate, endDate) {
var dates = [];
var finalDate = [];
var currDate = moment(startDate).startOf('day');
var lastDate = moment(endDate).startOf('day');
while (currDate.add(1, 'days').diff(lastDate) < 0) {
dates.push(currDate.clone().toDate());
}
console.log("All Dates: ", dates)
return dates;
}
This is how my console look like after running the code:
This is my firebase structure:
What I am trying to do is to merge/combine all the arrays of dates I am getting from my firebase list using the for loop to be one array with all dates
I have tried using the concat
method but it did not work, instead it adds the same array on the same array times the number of index. I have also tried this, but it's the same method I'm familiar with(the concat
method).
I need help in merging all my arrays from firebase to be in 1 array.