When working with typescript, I am faced with the challenge of dealing with two arrays:
interface IFirst{
name: string;
age: number
}
interface ISecond {
nickName: string;
lastName: string;
}
myFirstArray: IFirst[];
mySecondArray: ISecond[];
myFirstArray = [
{name: 'tim', age: 20},
{name: 'jim', age: 30}
]
I am trying to figure out a way to loop through myFirstArray and assign all names as nicknames in mySecondArray. Is there a method to achieve this functionality?
this.myFirstArray.forEach((element: IFirst) => {
this.mySecondArray.push({nickName = element.name});
})