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

139
Vistas
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 Respuestas
Responde la pregunta

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