Tengo la siguiente matriz:
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' }, ];Para id 102, ¿cómo actualizaría algunos o todos los valores clave para ese objeto dentro de la matriz?
Puede usar Array.find para encontrar el primer objeto en la matriz que coincida con la condición, que, en nuestro caso, es si la propiedad id es igual a 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);