Hey there, I have a rowdata that looks like this:
export const ROWDATA: Array<any> = [
{
id: "1",
start_time: "9:00:00",
end_time: "9:30:00",
day_of_week: 'monday',
lesson: "Lesson ABC",
class: "Class ABC",
room: "room1",
education_grade_subject: "Physics",
staff: "Amanda Jeremy",
timetable: "class timetable",
modified_user: "admin",
modified: "2017-01-15",
created_user: "admin",
created: "2017-01-15"
},
{
id: "2",
start_time: "9:30:00",
end_time: "10:00:00",
day_of_week: 'monday',
lesson: "Lesson XYZ",
class: "Class ABC",
room: "room2",
education_grade_subject: "Chemistry",
staff: "Amanda Jeremy",
timetable: "class timetable",
modified_user: "admin",
modified: "2017-01-15",
created_user: "admin",
created: "2017-01-15"
},
.....
];
This row data serves as the structure for a table on my website. The information is retrieved from the backend and now needs to be converted into a different format for the website. The new format should follow this pattern:
export const DATA: Array<any> = [
{
time: "9:00",
monday: [
{
class: 'room1',
title: {field: "lesson", text:"Lesson ABC", class:"lessonABC-title"},
content: [
{field: "education_grade_subject", text: "Physics", class:"lessonABC-subject-class"},
{field: "staff", text: "Amanda Jeremy", class:"lessonABC-staff-class"},
{field: "room", text: "Room 01", class:"lessonABC-room-class"}
],
uid: "1"
}
]
},
{
time: "9:30",
monday: [
{class: 'room2',
title: {field: "lesson", text:"Lesson XYZ", class:"lessonXYZ-title"},
content: [
{field: "education_grade_subject", text: "Chemistry", class:"lessonXYZ-subject-class"},
{field: "staff", text: "Amanda Jeremy", class:"lessonXYZ-teacher-class"},
{field: "room", text: "Room 02", class:"lessonXYZ-room-class"}
],
uid: "2"
}
]
},
....
The transformation of the second data is solely based on the first data provided. If you have any ideas or suggestions on how I can achieve this in JavaScript as I am relatively new to it, please share. Thanks in advance!