Can anyone tell me how can i achieve the following
activity = {} // can have hotel , transport etc
day = [ {day: 'DAY01'} , {day: 'DAY2'}]
i want to add activity.hotel to day 01 object in day array?
Can anyone tell me how can i achieve the following
activity = {} // can have hotel , transport etc
day = [ {day: 'DAY01'} , {day: 'DAY2'}]
i want to add activity.hotel to day 01 object in day array?
First get the precise day you want, for instance with find.
Then add a new key to the day object, by using the bracket notation, and assign your activity object.
let activity = { hotel: 'TheHotel' } // can have hotel , transport etc
let days = [ {day: 'DAY01'} , {day: 'DAY2'}]
// get the particular day to edit
let day = days.find(d => d.day === 'DAY01')
// attach the activity.hotel object you want.
day['hotel'] = activity.hotel;
console.log(days)
or add directly the whole activity object, if you want :
let activity = { hotel: 'TheHotel' } // can have hotel , transport etc
let days = [ {day: 'DAY01'} , {day: 'DAY2'}]
// get the particular day to edit
let day = days.find(d => d.day === 'DAY01')
// attach the activity object you want.
day['activity'] = activity;
console.log(days)