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.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *