Answer the question
In order to leave comments, you need to log in
How to fill one array through another using the constructor for the object inside?
Objective: Get people out. For example, an array of objects comes with api, but there is a lot of extra stuff in them, + I want to add some methods through the prototype constructor. For example:
export class Person {
constructor(
private name,
private sirname) {
this.name = name;
this.sirname = sirname;
}
getFullName() {
return `${this.name} + ${this.sirname}`;
}
}
response_persons = [
{
name: Vasya,
sirname: Pupkin,
id: 15,
avatar: '/imgs/avatar.jpg'
}
]
result_persons = []
response_persons.map(person => {
result_persons .push(new Person(person.name, person.sirname))
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question