Lädt...


🔧 JS - Shallow Copy and Deep Copy of an object


Nachrichtenbereich: 🔧 Programmierung
🔗 Quelle: dev.to

Shallow Copy
A shallow copy is a copy of an object whose references are the same as the original object. This means that if you change the value of a property in the shallow copy, it will also change the value of the property in the original object.

const user = {
    name: "Kingsley",
    age: 28,
    job: "Web Developer"
}
const clone = user

Methods -

Spread Operator(…): any object with a nested object will not be deep copied.

const originalObject = { name: "Alice", age: 25 };
const deepCopy =  {...originalObject};

deepCopy.name = "ravi"
console.log("originalObject", originalObject.name) // Alice

Object.assign(): the Object.assign() method should be used to deep copy objects that have no nested objects.

const originalObject = { name: "Alice", age: 25 };
const shallowCopy = Object.assign({}, originalObject);

Deep Copy
A deep copy is a copy of an object whose references are not the same as the original object. This means that if you change the value of a property in the deep copy, it will not change the value of the property in the original object.

Methods -
there different ways to create deep copy of an object.

a)JSON.parse and JSON.stringify: useful for nested object also.

 const originalObject = { name: "Alice", age: 25 };
   const deepCopy = JSON.parse(JSON.stringify(originalObject));

b)structuredClone:

const myDeepCopy = structuredClone(myOriginal);

Recursion:

function deepCopy(obj) {
       if (typeof obj !== 'object' || obj === null) {
           return obj;
       }
       const newObj = Array.isArray(obj) ? [] : {};
       for (let key in obj) {
           if (Object.hasOwnProperty.call(obj, key)) {
               newObj[key] = deepCopy(obj[key]);
           }
       }
       return newObj;
   }
   const originalObject = { name: "Alice", nested: { age: 25 } };
   const deepCopy = deepCopy(originalObject);
...

🕵️ CVE-2022-44108 | pdftojson 94204bb Object.cc Object::copy(Object*) stack-based overflow


📈 36.95 Punkte
🕵️ Sicherheitslücken

🔧 Why JavaScript Says "[object Object]" and Not Just "[object]" 🤔


📈 28.89 Punkte
🔧 Programmierung

🕵️ CVE-2022-33108 | XPDF 4.04 object.cc Object::Copy stack-based overflow


📈 27.88 Punkte
🕵️ Sicherheitslücken

🔧 How to deep copy a nested object in Javascript


📈 27.16 Punkte
🔧 Programmierung

🔧 Creating a deep copy of a JS Object


📈 27.16 Punkte
🔧 Programmierung

🍏 Copy 'Em 3.0.0 - Powerful clipboard menulet for copy and paste.


📈 21.14 Punkte
🍏 iOS / Mac OS

🍏 AnyMP4 DVD Copy for Mac 3.1.32 - Copy and burn DVD-discs.


📈 21.14 Punkte
🍏 iOS / Mac OS

🍏 Copy Fast 1.4.2 - Copy-and-paste contents of files with just a click.


📈 21.14 Punkte
🍏 iOS / Mac OS

📰 Microsoft Improves the Way We Copy and Paste with “Smart Copy”


📈 21.14 Punkte
📰 IT Security Nachrichten

🐧 Btrfs highlights in 5.5: 3-copy and 4-copy block groups


📈 21.14 Punkte
🐧 Linux Tipps

🔧 Advanced Java: Simplifying Object Property Copy and Manipulation with BeanUtil


📈 20.48 Punkte
🔧 Programmierung

🔧 Differences Between Object, {}, and object in TypeScript


📈 19.82 Punkte
🔧 Programmierung

🔧 The Differences Between 'Object', '{}', and 'object' in TypeScript


📈 19.82 Punkte
🔧 Programmierung

🔧 Understanding and Fixing "Object Reference Not Set to an Instance of an Object" in C#


📈 19.82 Punkte
🔧 Programmierung

🔧 Constants, Object.freeze, Object.seal and Immutable in JavaScript


📈 19.82 Punkte
🔧 Programmierung

🔧 How to Use CSS object-fit and object-position


📈 19.82 Punkte
🔧 Programmierung

📰 Windows 11: Aus Copy-Paste wird Copy-Advanced-Paste - Microsofts nächster Geniestreich mit KI?


📈 19.47 Punkte
📰 IT Nachrichten

📰 Windows 11: Aus Copy-Paste wird Copy-Advanced-Paste - Microsofts nächster Geniestreich mit KI?


📈 19.47 Punkte
📰 IT Nachrichten

📰 Windows 11: Aus Copy-Paste wird Copy-Advanced-Paste - Microsofts nächster Geniestreich mit KI?


📈 19.47 Punkte
📰 IT Nachrichten

🐧 Copy-Item: Copy Files Like a Boss in PowerShell


📈 19.47 Punkte
🐧 Linux Tipps

📰 Burpsuite-Copy-As-XMLHttpRequest - Copy As XMLHttpRequest BurpSuite Extension


📈 19.47 Punkte
📰 IT Security Nachrichten

📰 DVD Copy Software Review: How to Copy Your DVD Disc


📈 19.47 Punkte
📰 IT Security Nachrichten

🕵️ Low CVE-2016-10938: Copy-me project Copy-me


📈 19.47 Punkte
🕵️ Sicherheitslücken

🕵️ PC Floppy Copy Protection: Formaster Copy-Lock


📈 19.47 Punkte
🕵️ Reverse Engineering

🕵️ PC Floppy Copy Protection: Formaster Copy-Lock


📈 19.47 Punkte
🕵️ Reverse Engineering

🔧 Day 13: Deep Dive into Object Properties, Getters & Setters, and Lexical Scope in JavaScript 🎉


📈 19.1 Punkte
🔧 Programmierung

🔧 Javascript Object Assignments, Copy Or Reference?


📈 18.81 Punkte
🔧 Programmierung

🔧 Javascript Object Assignments, Copy Or Reference?


📈 18.81 Punkte
🔧 Programmierung

🔧 Copy Javascript Object from Safari Browser Console


📈 18.81 Punkte
🔧 Programmierung

🕵️ CVE-2022-41714 | fastest-json-copy 1.0.1 Object prototype pollution


📈 18.81 Punkte
🕵️ Sicherheitslücken

matomo