How to the modify the array of objects and return the latest updated field