I have array with objects users:
let state = {
users: [
{id: 1, name: 'Igor', selected: false},
{id: 2, name: 'Anton', selected: false},
{id: 3, name: 'Vasya', selected: false},
{id: 4, name: 'Pete', selected: false},
{id: 5, name: 'Dan', selected: false}
], ....
And a function that works with this object:
export function selectUser(userId) {
if (state.users.find(item => item.id == userId).selected == false) {
/* some code */
//[needed] Code to update the user property selected to true
} else {
/* some other code */
//[needed] Code to update the user property selected to true
}
emitChange();
}
How to do that, without overwriting the whole array, strangely can't think of anything