JavaScript - Combine Data From Two Arrays


2 min read

Using nested forEach loops to combine two arrays

To combine two arrays containing strings, one forEach loop can be nested inside another forEach loop:

1const times = ["00:00:00", "06:00:00", "12:00:00", "18:00:00"];
2const dates = ["2019-01-11", "2019-01-12", "2019-01-13", "2019-01-14"];
3const datesAndTimes = [];
4
5dates.forEach((date) => {
6 times.forEach((time) => {
7 this.datesAndTimes.push(date + " " + time);
8 });
9});
Previous post:
JavaScript - Convert A Date Object To A String
Next post:
How To Deploy A Web App To Heroku

Discussion