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

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

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