DEV Community

Mehul Lakhanpal
Mehul Lakhanpal

Posted on • Originally published at codedrops.tech

Destructuring nested object

Task: Destructuring response.body.count.

const response = {
  msg: "success",
  body: {
    count: 5,
    data: ["File 1", "File 2"],
  },
};

const {
  body: { count },
} = response;

console.log(count); // 5
Enter fullscreen mode Exit fullscreen mode

Here, first body is destructured, then count is destructured from body.


Thanks for reading 💙

Follow @codedrops.tech for daily posts.

InstagramTwitterFacebook

Micro-Learning ● Web Development ● Javascript ● MERN stack ● Javascript

codedrops.tech

Top comments (2)

Collapse
 
janpauldahlke profile image
jan paul

sweet ecmascript. i find you fluff and beatifull.
except undefined, NaN and null...

Collapse
 
saroj8455 profile image
Saroj Padhan

Thank you