-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5ObjectCloning.js
More file actions
24 lines (18 loc) · 793 Bytes
/
5ObjectCloning.js
File metadata and controls
24 lines (18 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// Object Cloning
// Note
// - When we clone the object and assign it to another object after that if we made any changes to original object it doesn't effect to the cloned
const object1 = {
name1: "value1",
name2: "value2",
name3: "value3",
};
// Clone object using spread operator
const object2 = { ...object1 };
console.log(object2);
// Q. What is Object.assign()?
// - It is use to copying object and assign to another object.
// - The Object.assign() method in JavaScript is used to copy the values of all enumerable properties from one or more source objects to a target object. It merges the properties of the source objects into the target object.
// SYNTAX
// Object.assign(targetObject, ...sourceObject);
const object3 = Object.assign({}, object1);
console.log(object3);