Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

249
Vistas
Given a key id, update few properties of one of the objects inside the array. How?

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?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

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)

about 4 years ago · Juan Pablo Isaza Denunciar

0

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);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda