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

176
Views
How to create a new array with the same content?

I use an external library to iterate over the array. It has the next() function to go to the next array item and returns false if there is no next item. If the next() is called the first time, then it returns the first item.

But here is how it works -

var a = ['item1'];
a.next(); // 'item1' is returned
...
a = ['item1']; // it could be called several times
a.next(); // false is returned, but 'item1' is expected

Is there any way to make a array to be treated as new array by next() function? I tried to add new elements to a (a.push(' ')) and it works well, but then I have to deal with an empty array elements.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

If it's a one dimensional array you could probably do something like:

let newArray = [...oldArray];

This would create a new array.

Can I ask you why you are using an external library to map over an array?

about 4 years ago · Juan Pablo Isaza Report

0

You could use the spread operator to create a shallow copy of that array.

var a = [1,2,3];
var b = [...a];

a.push(4);

console.log("a = " + a);
console.log("b = " + b);

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!