Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

83
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda