One has to be really careful with JSON solution! It doesn't work with values not compatible with JSON. Examples:
functionnestedCopy(array){returnJSON.parse(JSON.stringify(array));}// undefineds are converted to nullsnestedCopy([1,undefined,2])// -> [1, null, 2]// DOM nodes are converted to empty objectsnestedCopy([document.body,document.querySelector('p')])// -> [{}, {}]// JS dates are converted to stringsnestedCopy([newDate()])// -> ["2019-03-04T10:09:00.419Z"]
Consider using a library function if you have to work with such data.
One has to be really careful with JSON solution! It doesn't work with values not compatible with JSON. Examples:
Consider using a library function if you have to work with such data.
Wow.
This is really cool!
You have added a gem to the post!
Thanks!
Yes! Very good point, let me add that to the code notes! Thanks for noting that 👏