Retrieve the last element of an array, make changes to the object that received the value, but inadvertently modify the original last position as well, resulting in both objects being identical.
const lunchVisit = plannedVisits[plannedVisits.length - 1];
lunchVisit.visitPoint.name = 'lunch';
lunchVisit.lunch = true;
lunchVisit.waypoint.estimatedArrival = plannedVisits[plannedVisits.length - 1].waypoint.estimatedDeparture;
const lunchEndTime = new Date(plannedVisits[plannedVisits.length - 1].waypoint.estimatedDeparture);
lunchEndTime.setHours(lunchEndTime.getHours() + 2);
lunchVisit.waypoint.estimatedDeparture = lunchEndTime;
console.log(plannedVisits[plannedVisits.length - 1])
console.log(lunchVisit)
plannedVisits = [...plannedVisits, lunchVisit];