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

131
Visualizações
Array changes not seen (by other threads?)

I have a recursive function which performs the following things(among others), in that order:

  1. Prints the array A which is passed as a parameter
  2. Concatenates some new values into it: A=A.concat(localList);
  3. Prints the array A again
  4. Runs a for loop, each iteration of which calls the function again

While the print sandwich shows correct concatenation, I notice that different(parallel?) instances do not aknowledge the changes other make. Aren't arrays passed as reference?

I've included minimal info because I feel this is some basic fact I'm missing.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Array.concat returns a new instance. In order to keep the reference intact, you can concat a list like so:

yourarray.push.apply(yourarray, newitems)

Or more modern variant:

yourarray.push(...newitems)

To be clear, this will still not work if you're using multiple threads (Workers) since objects passed between Workers are cloned.

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