Hello guys I am trying to push a new element to all the objects in an array but seem to not update.
Any idea what am I doing wrong in here?
So this is my object which contain the instalments array.
{ _id: 5cf7d4fcc9c5846a69b48d41,
offer: 5cf7d4fcc9c5846a69b48d40,
instalments:
[ { paid: false,
_id: 5cf7d4fcc9c5846a69b48d44,
description: 'Some deacription about yhis instalment',
instalmentAmount: 100000,
dueTo: 2019-06-06T23:00:00.000Z },
{ paid: false,
_id: 5cf7d4fcc9c5846a69b48d43,
description: 'Some deacription about yhis instalment',
instalmentAmount: 100000,
dueTo: 2019-06-13T23:00:00.000Z },
{ paid: false,
_id: 5cf7d4fcc9c5846a69b48d42,
description: 'Some deacription about yhis instalment',
instalmentAmount: 91152,
dueTo: 2019-06-20T23:00:00.000Z } ],
user: 5cf53a1a8481923f72939940,
createdAt: 2019-06-05T14:43:08.706Z,
updatedAt: 2019-06-05T14:43:08.706Z,
__v: 0 }
What I want to do is to add offer to all instalments objects
The way I am trying to do this is as follow.
instalmentsGroup is the object above then I access instalments and map
const instalments = await instalmentsGroup.instalments.map(
instalment =>
Object.assign({}, instalment, { offer: instalmentsGroup.offer })
);