I have the following array:
let tblUsers = [
{ id: 101, user: 'user1', password: 'password1', created: '2021-01-01 23:59:59', modified: '2021-01-01 23:59:59', status: 'Active', firstName: 'Bob', lastName: 'Marley' },
{ id: 102, user: 'user2', password: 'password2', created: '2021-01-01 23:59:59', modified: '2021-01-01 23:59:59', status: 'Inactive', firstName: 'Bill', lastName: 'Murray' },
{ id: 103, user: 'user3', password: 'password3', created: '2021-01-01 23:59:59', modified: '2021-01-01 23:59:59', status: 'Active', firstName: 'Jeniffer', lastName: 'Connelly' },
];
For id 102, how would I update some or all key-values for that object inside the array?
You can use Array.find to find the first object in the array which matches the condition, which, in our case, is whether the id property is equal to 103:
let tblUsers = [
{ id: 101, user: 'user1', password: 'password1', created: '2021-01-01 23:59:59', modified: '2021-01-01 23:59:59', status: 'Active', firstName: 'Bob', lastName: 'Marley' },
{ id: 102, user: 'user2', password: 'password2', created: '2021-01-01 23:59:59', modified: '2021-01-01 23:59:59', status: 'Inactive', firstName: 'Bill', lastName: 'Murray' },
{ id: 103, user: 'user3', password: 'password3', created: '2021-01-01 23:59:59', modified: '2021-01-01 23:59:59', status: 'Active', firstName: 'Jeniffer', lastName: 'Connelly' },
];
const user3 = tblUsers.find(user => user.id == 103)
user3.status = 'Inactive';
console.log(tblUsers)
let tblUsers = [
{ id: 101, user: 'user1', password: 'password1', created: '2021-01-01 23:59:59', modified: '2021-01-01 23:59:59', status: 'Active', firstName: 'Bob', lastName: 'Marley' },
{ id: 102, user: 'user2', password: 'password2', created: '2021-01-01 23:59:59', modified: '2021-01-01 23:59:59', status: 'Inactive', firstName: 'Bill', lastName: 'Murray' },
{ id: 103, user: 'user3', password: 'password3', created: '2021-01-01 23:59:59', modified: '2021-01-01 23:59:59', status: 'Active', firstName: 'Jeniffer', lastName: 'Connelly' },
];
const objectToChange = tblUsers.find((obj) => obj.id === 102);
objectToChange.user = 'user111';
console.log(tblUsers);