this.groups = [{..},{..},...] addGroup = {..} updateGroupToList(addGroup){ this.groups.forEach(element => { if(element.id==addGroup.id){ element = addGroup; } return ???; }); }
updateGroupToList(addGroup){ let index = this.groups.findIndex(({id}) => id == addGroup.id); this.groups[index] = addGroup; return this.groups; }
updateGroupToList(addGroup){ this.groups = this.groups.map(element => { if (element.id === addGroup.id) { element = addGroup; } return element; }); }