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

84
Vistas
Array find method without mutation

I have a function as below which finds a particular element in an array of objects and updates it:

async update(id, attrs){
    const records = await this.getAll();
    const record = records.find(record => record.id === id);
    Object.assign(record, attrs);
    await this.writeAll(records);

}

I was surprised to understand the find method returns a reference to the matching element in the records array whereas I was expecting that the record variable would just contain the value and changing it would not cause the original records array to get updated.

So my question is, what if I just want to retrieve the value from an object array but not a reference to the actual element? that is, I need to be able to update the returned value without mutating the original array.

about 4 years ago · Juan Pablo Isaza
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