0

Right now to make a new object out of an existing object I stringify it, then parse it into a new variable. Is there a better way?

eg:

let newObject = JSON.parse(  JSON.stringify(originalObject)  )
David Alsh
  • 6,747
  • 6
  • 34
  • 60
  • 1
    `Object.assign(target, [object,...])` – Rajesh Mar 24 '17 at 08:42
  • Do you want a "deep" copy of nested objects/arrays? Note that the way you've shown assumes the object can be stringified, which not all can so it could result in an error. – nnnnnn Mar 24 '17 at 08:42
  • Note, `JSON.parse(JSON.stringify())` approach will ignore function – Rajesh Mar 24 '17 at 08:44

0 Answers0