From the course: JavaScript Patterns: Modern Solutions to Common Challenges

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Solution: JSON.stringify() and JSON.parse()

Solution: JSON.stringify() and JSON.parse()

- [Instructor] In this video, we'll address how to make actual copies of objects in JavaScript. There is, as far as I know, anyway, no completely simple answer to this question, but there are good ones. We just need to consider what's in our objects before we choose one. So I'd recommend loading up the index.html file for this example in your browser before we start. Back here in my editor, I have the JavaScript file that goes with the example, and I've made my kitty object a little more complex here. I have the same properties as I did before, basic strings and a number, but I also have a key called offspring, which contains an array. This is all the kittens that this kitty might've had. An object for their best friend, which let's say here is a parakeet named crackers, and then a function called meow, which will return a string where the kitty says meow, and we get their own name. So we have a few different types…

Contents