I am looking for a way in javascript to pass data from an object of one type to another of a different type.
The first object would be this
(6) [{…}, {…}, {…}, {…}, {…}, {…}]
0:
date: "2018-03-29T13:34:00.000+0200"
location:
locationx: "Almacen"
id: 21
__proto__: Object
id: 7
__proto__: Object
Now I want to pass the locationx and date data to another object with this structure.
pr: EventInput[] = [
{
title: '', // Aquí seria locationx
start: '', // Aquí seria date
},
{
title: '',
start: '',
},
];
Keep in mind that there can be hundreds of data, any ideas? Thank you
EDIT
In FullCalendar I have to get the initial events from an http request.
export class AppComponent implements OnInit {
constructor(
private vacationService: VacationService,
) {}
ngOnInit(): void {
this.loadEvents();
}
pr: EventInput[] = [
{
title: 'All-day event',
start: '2021-05-16',
},
{
title: 'All-day event',
start: '2021-05-18',
},
];
calendarOptions: CalendarOptions = {
initialView: 'dayGridMonth',
headerToolbar: {
left: '',
center: 'title',
},
editable: true,
initialEvents: this.pr,
};
loadEvents(): void {
this.vacationService.getAll().subscribe((data) => {
// My data
console.log(data);
})
}
}
The pr variable contains the initial events that I can do manually but I need them to be from the data of my request to the database. In other words, I need to pass the data to the pr variable, taking into account that they have a different structure.
You can use the function
Array.map
for that purpose.Assuming that the initial array is stored in
data
: