Trying to utilize JavaScript to transform the given array into a JavaScript object, but unsure of the process.
The input array is structured such that each key corresponds to a day of the week (Sunday to Saturday); where key 0 represents Sunday, key 1 represents Monday, and so forth up to key 6 representing Saturday.
var times = [["8:30-12:00","14:00-18:00"],
["6:15-9:30","13:00-16:00","20:00-23:15"],[],["9:00-21:00"],
["9:00-21:00"],[],[]];
The goal is to convert the above times
array into the following JavaScript object:
timeObj = {
sunday: [
{
start: '08:30',
stop: '12:00'
},
{
start: '14:00',
stop: '18:00'
}
],
monday: [
{
start: '06:15',
stop: '9:30'
},
{
start: '13:00',
stop: '16:00'
},
{
start: '20:00',
stop: '23:15'
}
],
tuesday: [],
wednesday: [
{
start: '9:00',
stop: '21:00'
}
],
thursday: [
{
start: '9:00',
stop: '21:00'
}
],
friday: [],
saturday: []
};
What is the recommended method to achieve this transformation from the times
array to the timeObj
object?