How can you destructure nested properties in objects using JavaScript?
- const { prop1.prop2 } = myObject;
- const { prop1: { prop2 } } = myObject;
- const [ prop1, prop2 ] = myObject;
- const { prop1[prop2] } = myObject;
To destructure nested properties in JavaScript objects, you should use the syntax in Option 2. It allows you to access nested properties within myObject. The other options either contain incorrect syntax or won't work for this purpose.
Loading...
Related Quiz
- In Pug, to extend a layout, you use the extends keyword and to fill a block within the layout, you use the ______ keyword.
- In what scenario would you need to create a custom error class in Express.js?
- Which of the following strategies can be used to efficiently serve static assets and optimize performance?
- In a token-based authentication system, using a ______ approach helps in reducing the risk of token interception and replay attacks.
- You are developing a web application that needs to make API requests to a server on a different domain. How would you handle CORS to ensure that your web application can interact with the server without any issues?