Hi Tuan Tran, thanks for stopping by and your question about JSON.parse() and JSON.stringify().

I updated the article to add 3 more methods of deep copy: a custom function, JSON.parse/JSON.stringify, and the rfdc (Really Fast Deep Clone) library.

Kevin Dalman correctly points out that JSON.parse() and JSON.stringify() only work for nested objects and arrays that contain only primitive values, objects, and arrays — Date and RegExp objects are examples that will not work correctly.

I demonstrate some of these examples of JSON.parse() and JSON.stringify() in the updated article on how to deep copy, so please take a look!

Alexis Chappron is definitely right that parse & stringify can be slower than a custom function or rfdc, though it will generally be faster (for the data types it works with) than lodash’s _.cloneDeep functionality.

Alexis also pointed out that parse & stringify will fail for circular references, though rfdc is the only deep copy method I cover that expects circular references with an optional flag.

🤓 The physical therapist who writes JavaScript 💪 Web Developer 😎 Mentor 🧠 DPT 😄 SEO Expert 😁 React 😆 Jamstack 💬 Ask me anything 👉 DoctorDerek.com 👈

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store