0

Hell,

I have this line...

const tempStage = Object.assign({}, stage)

stage is an object type. Whenever I manipulate tempStage it affects stage.

Doing something like this for example changes the corresponding value in stage...

tempStage['$']['stageid']= "1234"

Can I get these two things to be independent of one another?

SonOfNye
  • 75
  • 8
  • You could try cloning the object. `const tempStage = JSON.parse(JSON.stringify(object))`, if there are no dates in the object. https://stackoverflow.com/questions/728360/how-do-i-correctly-clone-a-javascript-object – Robert Harvey Apr 03 '20 at 19:50
  • 2
    Does this answer your question? [JS: Does Object.assign() create deep copy or shallow copy](https://stackoverflow.com/questions/34504682/js-does-object-assign-create-deep-copy-or-shallow-copy) – Joe Apr 03 '20 at 19:50
  • You need a deep copy for nested objects - e.g. lodash's `cloneDeep` – Joe Apr 03 '20 at 19:50

0 Answers0