In my Angular application, I am encountering an issue while trying to add values to an array within a block of code.
Even though I have defined the variable 'contactWithInitials', I keep receiving an error message stating 'Cannot read property push of undefined'.
What could be causing this problem?
let initialHold: any;
let contactWithInitials: any [];
this.contacts.forEach( eachObj => {
if(eachObj.first_name){
initialHold = eachObj.first_name.charAt(0);
}
if(eachObj.last_name){
initialHold += eachObj.last_name.charAt(0);
}
contactWithInitials.push({'userInitials':initialHold});
})