Combine Arrays in a firebase for loop javascript












0















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:
enter image description here



This is my firebase structure:
enter image description here



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.










share|improve this question

























  • Where are you concating the output array inside the for loop?

    – Hassan Imam
    Nov 26 '18 at 11:45











  • I've removed that line, I will add it back just now but it's on the enumerateDaysBetweenDates() method outside the while loop.

    – Zack
    Nov 26 '18 at 11:47













  • Instead of using array#forEach, you can use array#reduce and concat your array.

    – Hassan Imam
    Nov 26 '18 at 11:50











  • Thanks, let me try that now.

    – Zack
    Nov 26 '18 at 11:53











  • Good luck, in case you face any issue revert here.

    – Hassan Imam
    Nov 26 '18 at 11:54
















0















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:
enter image description here



This is my firebase structure:
enter image description here



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.










share|improve this question

























  • Where are you concating the output array inside the for loop?

    – Hassan Imam
    Nov 26 '18 at 11:45











  • I've removed that line, I will add it back just now but it's on the enumerateDaysBetweenDates() method outside the while loop.

    – Zack
    Nov 26 '18 at 11:47













  • Instead of using array#forEach, you can use array#reduce and concat your array.

    – Hassan Imam
    Nov 26 '18 at 11:50











  • Thanks, let me try that now.

    – Zack
    Nov 26 '18 at 11:53











  • Good luck, in case you face any issue revert here.

    – Hassan Imam
    Nov 26 '18 at 11:54














0












0








0








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:
enter image description here



This is my firebase structure:
enter image description here



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.










share|improve this question
















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:
enter image description here



This is my firebase structure:
enter image description here



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.







javascript arrays firebase firebase-realtime-database






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 11:36









André Kool

3,43092740




3,43092740










asked Nov 26 '18 at 11:28









ZackZack

1539




1539













  • Where are you concating the output array inside the for loop?

    – Hassan Imam
    Nov 26 '18 at 11:45











  • I've removed that line, I will add it back just now but it's on the enumerateDaysBetweenDates() method outside the while loop.

    – Zack
    Nov 26 '18 at 11:47













  • Instead of using array#forEach, you can use array#reduce and concat your array.

    – Hassan Imam
    Nov 26 '18 at 11:50











  • Thanks, let me try that now.

    – Zack
    Nov 26 '18 at 11:53











  • Good luck, in case you face any issue revert here.

    – Hassan Imam
    Nov 26 '18 at 11:54



















  • Where are you concating the output array inside the for loop?

    – Hassan Imam
    Nov 26 '18 at 11:45











  • I've removed that line, I will add it back just now but it's on the enumerateDaysBetweenDates() method outside the while loop.

    – Zack
    Nov 26 '18 at 11:47













  • Instead of using array#forEach, you can use array#reduce and concat your array.

    – Hassan Imam
    Nov 26 '18 at 11:50











  • Thanks, let me try that now.

    – Zack
    Nov 26 '18 at 11:53











  • Good luck, in case you face any issue revert here.

    – Hassan Imam
    Nov 26 '18 at 11:54

















Where are you concating the output array inside the for loop?

– Hassan Imam
Nov 26 '18 at 11:45





Where are you concating the output array inside the for loop?

– Hassan Imam
Nov 26 '18 at 11:45













I've removed that line, I will add it back just now but it's on the enumerateDaysBetweenDates() method outside the while loop.

– Zack
Nov 26 '18 at 11:47







I've removed that line, I will add it back just now but it's on the enumerateDaysBetweenDates() method outside the while loop.

– Zack
Nov 26 '18 at 11:47















Instead of using array#forEach, you can use array#reduce and concat your array.

– Hassan Imam
Nov 26 '18 at 11:50





Instead of using array#forEach, you can use array#reduce and concat your array.

– Hassan Imam
Nov 26 '18 at 11:50













Thanks, let me try that now.

– Zack
Nov 26 '18 at 11:53





Thanks, let me try that now.

– Zack
Nov 26 '18 at 11:53













Good luck, in case you face any issue revert here.

– Hassan Imam
Nov 26 '18 at 11:54





Good luck, in case you face any issue revert here.

– Hassan Imam
Nov 26 '18 at 11:54












0






active

oldest

votes












Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53480149%2fcombine-arrays-in-a-firebase-for-loop-javascript%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53480149%2fcombine-arrays-in-a-firebase-for-loop-javascript%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Costa Masnaga

Fotorealismo

Sidney Franklin