DEV Community

Mehul Lakhanpal
Mehul Lakhanpal

Posted on • Originally published at

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 for daily posts.


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

Top comments (2)

janpauldahlke profile image
jan paul

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

saroj8455 profile image
Saroj Padhan

Thank you