Join Slack
Powered by
<@U8CT0V220> Actually according to some article I ...
# suitescript
a
alien4u
02/13/2019, 9:30 PM
@jkabot
Actually according to some article I read some time ago which I can't find now, one of the best ways to make an object copy is using
JSON.parse()
and
JSON.stringify
...
a
Ankur Sanghi
02/13/2019, 9:34 PM
Found this link that says that stringify and parse is good enough for a simple JSON object:
https://we-are.bookmyshow.com/understanding-deep-and-shallow-copy-in-javascript-13438bad941c
👍 1
s
stalbert
02/13/2019, 10:26 PM
the idiomatic way to copy an object in 2019 is probably
Copy code
let newobj = { ...oldobj }
j
jkabot
02/13/2019, 10:31 PM
I usually use spread too, but to be fair I think it only clones "one level deep"
s
stalbert
02/13/2019, 10:31 PM
aye
stalbert
02/13/2019, 10:32 PM
JSON.stringify() doesn't walk the prototype chain either... so only owned props get serialized.
Open in Slack
Previous
Next