How can you create a deep copy of an object in JavaScript?
- JSON.parse(JSON.stringify(object))
- object.copy()
- deepCopy(object)
- Object.clone(object)
To create a deep copy of an object in JavaScript, you can use JSON.parse(JSON.stringify(object)). This method serializes the object to a JSON string and then parses it back into a new object, effectively creating a deep copy. The other options are not valid for deep copying objects.
Loading...
Related Quiz
- How can you optimize the rendering performance of template engines like EJS and Pug?
- You are working on a project with tight deadlines, and there is limited time for testing. How would you prioritize testing activities to ensure the quality of the application without compromising the timeline?
- How can the design of the Event Loop and Non-Blocking I/O lead to potential pitfalls in application behavior, such as callback hell or race conditions?
- When performing CRUD operations on a database, which operation can be the most expensive in terms of performance?
- What is the significance of the 'backpressure' concept in streams in Node.js?