For some reason, I can't seem to add a new element to an array in my code. I'm not sure what's going wrong. Here is the snippet:
buildContactsCollection(primaryContact: Card){
if(primaryContact.phones === undefined){
primaryContact.phones = []
}
let primaryPhone = this.formatPhoneNumber(primaryContact.mobileRawNumber, primaryContact.mobile)
console.log("in build collection primary phone is", primaryPhone)
if(primaryPhone !== undefined){
console.log("before phones are:", primaryContact.phones)
primaryContact.phones.push({
"type" : "personal",
"phoneType": "mobile",
"extn": "",
"rawNumber": primaryPhone
})
console.log("after pushing:", primaryContact)
}
The definition of the card object used is as follows:
export class Card {
private _mobile:string
private _mobileRawNumber:string
private _phones:Object[]
get mobile():string{
return this._mobile
}
set mobile(val:string){
this._mobile = val
}
get mobileRawNumber():string{
return this._mobileRawNumber
}
set mobileRawNumber(val:string){
this._mobileRawNumber = val
}
get phones(): Object[]{
if(this._phones === undefined)
this._phones = []
return this._phones
}
set phones(val:Object[]){
this._phones = val
}
Despite having a valid value for primaryPhone, the console output indicates that no new object is being pushed to the phones array.