Skip to content

Commit

Permalink
Update JS.js
Browse files Browse the repository at this point in the history
add js deep copy options
  • Loading branch information
beumsk committed Nov 15, 2024
1 parent 9ac2c60 commit eadbe7f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions JS.js
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,16 @@



// DEEP COPY
// opposed to shallow copy, deep copy doesn't hold reference, even for nested objects and arrays
const obj1 = { id: 1, name: "one", user: { id: 1, name: "user1", start: new Date() } };
const deep1 = { ...obj1, user: { ...obj1.user } }; // fast but verbose
const deep2 = JSON.parse(JSON.stringify(obj1)); // slower (switch dates to string!)
const deep3 = structuredClone(obj1); // slowest




// POP-UPS
// launch pop-up

Expand Down

0 comments on commit eadbe7f

Please sign in to comment.