Javascript 2
Javascript 2
for Objects
var person = { name: 'Max' }
var copiedPerson = Object.assign({}, person)
let student1 = {
name: "Manish",
company: "Gfg"
}
let student2 = JSON.parse(JSON.stringify(student1))
Here's one super-important thing to note though: You're not creating deep clones
with either approach!
If you cloned array contains nested arrays or objects as elements or if your
object contains properties that hold arrays or other objects, then these nested
arrays and objects will not have been cloned!
You still have the old pointers, pointing to the old nested arrays/ objects!
You'd have to manually clone every layer that you plan on working with. If you
don't plan on changing these nested arrays or objects though, you don't need to
clone them.
Here's one super-important thing to note though: You're not creating deep clones
with either approach!
If you cloned array contains nested arrays or objects as elements or if your
object contains properties that hold arrays or other objects, then these nested
arrays and objects will not have been cloned!
You still have the old pointers, pointing to the old nested arrays/ objects!
You'd have to manually clone every layer that you plan on working with. If you
don't plan on changing these nested arrays or objects though, you don't need to
clone them.
https://redux.js.org/usage/structuring-reducers/immutable-update-
patterns#immutable-update-patterns