Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

115
Views
Unpacking fields from nested objects passed as a parameter

How can I unpack nested object passed as a parameter? I want to unpack age from the object how can I do that?

const user = {
  id: 42,
  username: "usrname",
  info: {
    fullName: "John",
    age: 15
  }
};

function foo({ username: usrnam, info }) {
  return `${usrnam} ${info} `;
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can destructure any level as:

{ username: usrnam, info: { age } }

or, if you don't want to assign to a new variable name then:

{ username, info: { age } }

const user = {
  id: 42,
  username: "usrname",
  info: {
    fullName: "John",
    age: 15,
  },
};

function foo({ username: usrnam, info: { age } }) {
  return `${usrnam} ${age} `;
}

console.log(foo(user));

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!