I have an angular project where I have a block of code that returns an array of objects, which consists of contact records.
I have a 'forEach' loop where I create a new field with the user's initials.
I want to then push this new field 'userInitials' into the appropriate record.
I have the following code, but it's pushing new objects and not new fields, but when I remove the object brackets, I get 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});
})