My current array consists of various time values, such as:
// '6:00pm',
// '7:00pm',
// '8:00pm',
// '9:00pm',
// '10:00pm',
// '11:00pm',
// '12:00am',
// '1:00am',
// '2:00am',
// '3:00am',
// '4:00am',
// '5:00am',
// '6:00am',
// '7:00am',
// '8:00am',
// '9:00am',
// '10:00am',
// '11:00am',
// '12:00pm',
// '1:00pm',
// '2:00pm',
// '3:00pm',
// '4:00pm',
// '5:00pm',
I am looking to format these times into objects like the example below:
[
{
time: "6:00",
Meridiem: "pm"
},
{
time: "7:00",
Meridiem: "pm"
}
]
However, I am facing a roadblock when trying to loop through the times and need assistance. My attempted solution so far includes:
const array = new Array(12);
let timeArray = [];
for(var i=1;i<=array.length;i++){
let x = {
time: i,
meridium: "AM"
}
timeArray.push(x);
};
console.log(timeArray, 'timeArray')
I am aware that this is not correct. Could someone provide guidance on how to achieve the desired output?