Can I pass nested object in as a parameter

Tell us what’s happening:
I am currently on the following algorithms and I am just curious if we can pass nested objected as follows

const half = ({stats{max, min}}) => (stats.max + stats.min) / 2.0; 

as I remember nested deconstruction was done like that. so I am curious to know if this is the right format too.

  **Your code so far**
const stats = {
max: 56.78,
standard_deviation: 4.34,
median: 34.54,
mode: 23.87,
min: -0.75,
average: 35.85

// Only change code below this line
const half = ({max, min}) => (max + min) / 2.0; 
// Only change code above this line
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36

Challenge: ES6 - Use Destructuring Assignment to Pass an Object as a Function’s Parameters

Link to the challenge:

There is only one object and that is passed to the function and gets destructured.

The object would have to have nested objects for what you are asking to make sense.

const user = {
  name: 'John',
  age: 30,
  location: {
    city: 'London',
    country: 'UK'

const { name, age, location: { city, country } } = user
console.log(name, age, city, country); // John 30 London UK

// Function parameter destructuring example
const getUserProps = ({ name, age, location: { city, country } }) => {
  console.log(name, age, city, country); // John 30 London UK


yep, thank you. I wanted to confirm if that would work. seems like I m learning :heart_eyes:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.