1

I want to get these properties from an object using es6 directly on the parameters list of the function but I don't know how to do it exactly:

    function methodA(person){
       var driverName = person.name,
       age = person.age,
       company = person.job.company;
       ...
    }

Any tips in that direction?

  • For more info: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Basic_assignment – kind user Dec 09 '18 at 14:15

1 Answers1

1

Take a destructuring assignment.

function methodA(person) {
    var { name: driverName, age, job: { company } } = person;
    console.log(driverName, age, company);
}

methodA({ name: 'Grace', age: 49, job: { company: 'Infinity' } })
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392