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

177
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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