Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

128
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!