Skip to content
Advertisement

javascript add up date and time object in an array

so I have a list of array of time and date I want to join both appointmateDate and appointmentTime to iso format and get a new array of timeRange is that possible🙏🏻

JavaScript

Advertisement

Answer

Using setHours.

Loop over the array using Array#map and create a new Date object using appointmentDate and then using setHours and appointmentTime set the time.

NOTE: 20:51 am is not a valid time, if it is in 24 hour format there’s no need for am, pm.

JavaScript

One Liner

Logic remains exactly the same, its just expressions instead of statements.

JavaScript
Advertisement