I have such a method:
public getContentForGivenFields(fields: any) {
this.content$.subscribe({
next: res => {
console.log(res.fields); // res.first_name => {first_name object}
}
})
}
And the 2nd method that calls the 1st one:
public getPersonName() {
this.service.getContentForGivenFields("first_name");
}
I want the first method to take its parameter and use it in the way that I showed above. If you know another way - please, share!
Thanks :)
CodePudding user response:
You want to pass few names and concatenate those fields? or just one property?
if one then res[fieldName]
otherwise fields.map(field => res[field]).join(' ')
or sth similar;
or you can use pluck
operator and then concatenate result