below is part of my code
this.diaryToEdit.diaryStatus.statusName = updatedDiary.diaryStatus.statusName;
this.diaryToEdit.diaryStatus.statusId = updatedDiary.diaryStatus.statusId;
this.diaryToEdit.actioDate = new Date(updatedDiary.actioDate);
this.diaryToEdit.actionText = updatedDiary.actionText;
this.diaryToEdit.diaryType = updatedDiary.diaryType;
Similary there are more properties which needs to be updated in this.diaryToEdit
with updatedDiary
values. Instead of writing like above, is there any better way to format code. Please suggest.
2
Answers
you could use spread syntax.
note that this will create a new object with modified values.
It depends on your needs, i.e. if you want to clone the information first, or if you only need to keep some data contained in "updatedDiary", etc…
If it’s okay (don’t clone and keep any info) I’d probably re-write it like this:
Otherwise it is better to create a clean copy:
But I repeat, it depends on your needs and possibly on the type of data you are cloning.