割り当てオブジェクトが
代わりに、コピーを作成し、おそらくES2018のプロパティスプレッドを使用して、プロパティをコピーに追加します。
allocation = {...allocation, timestamp: moment(allocation.end_date).format('x')};
...または、プロパティスプレッドを使用できない場合は、Object.assign :
allocation = Object.assign({}, allocation, {timestamp: moment(allocation.end_date).format('x')});
constを変更する必要があります let どちらの場合も、変数allocationが保持する値を変更しているためです。 。または、もちろん、constのままにしておきます 変更したバージョンを個別に覚えておいてください:
const updatedAllocation = {...allocation, timestamp: moment(allocation.end_date).format('x')};
response.status(200).send(updatedAllocation);
正しい。 const 変数に適用されます (allocation )、変数が参照するオブジェクトではありません。