I am getting my data from localestorage and saving to my personalInfo object, later i want to send this object to my API, but for some cases my underageChildInfo and beneficiaryInfo wont exist and i get error. how can i remove my array from this object if it doesnt exist in localestorage?
this.data = JSON.parse(localStorage.getItem('policy'));       
get info(): any {
         return this.personalInfo = {
            personalInfoId: 0,
            insurerInfo: {
               firstName:  this.data.calculatorInfo.name,
               lastName : this.data.calculatorInfo.surname,
               phoneNumber: this.data.contactInfo.phone,
               email: this.data.contactInfo.email
            },
            underageChildInfo: this.data.underageChildInfo.map(i =>
              ({
              firstName: i.name,
              lastName: i.surname,
              birthDate: i.birthDate
            })),
            beneficiaryInfo:
            this.data.beneficiaryInfo.map(i =>({
              firstName: i.name,
              lastName: i.surname
            }))
          }
       }
  onSubmit() {
    console.log(this.info);
}
 
    