DEV Community


Destructuring nested object

Mehul Lakhanpal
Full stack Developer | Micro-blogging on Web Development at | Creator of File Ops, Note Box, GitHub Marker
Originally published at ・1 min read

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

Discussion (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