i have an array like this :
const toto = [{ id: 1, arrays: [{ id: 1, name: 'tatat' }, { id: 2, name: 'tutu' }] };
And i'd like to get :
[{ id: 1, arrays: [{ id: 1, name: 'tatat' }] }, { id: 1, arrays: [{ id: 2, name: 'tutu' }] }];
This is what i did :
const aEvt = [];
this.organization.events.forEach(x => {
const e = Object.assign({}, x);
if (x.eventToOrganizators.length > 1) {
x.eventToOrganizators.forEach(y => {
console.log('y', y);
e.eventToOrganizators = [y];
console.log('e', e.eventToOrganizators[0]); // OK get the good value
aEvt.push(e);
});
} else {
aEvt.push(e);
}
});
console.log(aEvt); // NOT OK, e.eventToOrganizators[0] has all the time the same value