• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
JavaScriptSource

JavaScriptSource

Search 5,000+ Free JavaScript Snippets

  • Home
  • Browse Snippets
    • Addon
    • Ajax
    • Buttons
    • Cookies
    • CSS
    • Featured
    • Forms
    • Games
    • Generators
    • Image Effects
    • Math Related
    • Miscellaneous
    • Multimedia
    • Navigation
    • Page Details
    • Passwords
    • Text Effects
    • Time & Date
    • User Details
Home / Miscellaneous / Deep clone a value in Node.js

Deep clone a value in Node.js

Deep clone a value in Node.js

If you want to deep clone a value in Node.js, you no longer need to use a library or the JSON.parse(JSON.stringify(value)) hack. You can use the new global function structuredClone()


const user = {
  name: "JS Snippets",
  address: { street: "Original Road", city: "Placeshire" },
};

const clonedUser = structuredClone(user);

clonedUser.address.street = "New Road";

console.log("user.address.street:", user.address.street);
// > Original Road

console.log("clonedUser.address.street:", clonedUser.address.street);
// > New Road

Source

https://github.com/roeib/JavaScript-snippets#structuredclone

Miscellaneous

Related Snippets:

  • Xmas Tree Generator
  • Return all elements in an array except for the first one
  • Replace a portion of a string with something else
  • Remove an item from an object

Primary Sidebar

Popular Posts

Story Generator

IP Grabber – get a users IP address with JavaScript

Simple Calendar

Remove Ads

Astrological Calculator

Copyright © 2025 JavaScriptSource.com

  • About
  • Privacy Policy
  • FAQ
  • Jobs For Developers