Search code examples
javascriptarraysobjectjavascript-objects

Is it possible to use destructuring to declare in less lines of code this decalarations?


Is it possible to use destructuring to declare in less lines of code this decalarations?

const identification_type = this.phaseOneForm.controls.identification_type.value;
const identification_number =this.phaseOneForm.controls.identification_number.value;
const date_of_issue = this.phaseOneForm.controls.date_of_issue.value;
const date_of_birth = this.phaseOneForm.controls.date_of_birth.value;
const pep = this.phaseOneForm.controls.pep.value;
const us = this.phaseOneForm.controls.us.value;
const qualified_investor = this.phaseOneForm.controls.qualified_investor.value;

I tried:

const {
  value: identification_type,
  value: identification_number,
  value: date_of_issue,
  value: date_of_birth,
  value: pep,
  value: us,
  value: qualified_investor,
} = this.phaseOneForm.controls;

But does not work


Solution

  • your syntax is not completely correct

    const {
        identification_type: {
            value: identification_type
        },
        identification_number : {
            value: identification_number 
        },
        date_of_issue: {
          value: date_of_issue
        },
        date_of_birth : {
            value: date_of_birth 
        },
        pep : {
            value: pep 
        },
        us : {
            value: us 
        },
        qualified_investor : {
            value: qualified_investor 
        }
    } = this.phaseOneForm.controls;