In my Angular project, I have a specific code block that retrieves an array of objects containing contact records.
Within a 'forEach' loop, I am generating a new field for each contact record to store the user's initials.
The goal is to add this newly created 'userInitials' field to the appropriate record in the array.
I attempted the following code snippet, however, it seems to be adding new objects instead of new fields. Removing the object brackets results in errors.
let initialHold: any;
let contactWithInitials = [];
this.contacts.forEach( eachObj => {
if(eachObj.first_name){
initialHold = eachObj.first_name.charAt(0);
}
if(eachObj.last_name){
initialHold += eachObj.last_name.charAt(0);
}
this.contacts.push({'userInitials':initialHold});
})