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

111
Visualizações
Save a changing variable in javascript

In my code I want to save an object that changes during the execution in an array inorder to use it after the execution of the function,so I tried to create a copy of it using this approach:

let copy=[...original]//original is the variable that changes during the execution when I used this approach I noticed that the content of the copied array is the same as the last value of the original array. Now I need a method that can keep all the states of the original array in one variable.

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

0

You can give a try to structuredClone() method which help you in creating a deep clone of a given value using the structured clone algorithm.

// Create an object with a value
const original = { name: "Alpha" };

// Clone it
const clone = structuredClone(original);

// Change original object value in execution
original.name = 'Beta';

console.log(original); // { "name": "Beta" }
console.log(clone); // { "name": "Alpha" }
console.log(clone !== original); // true

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