I have one third Party API which returns data as below -
It has been called from Angular Service using HttpClient.
const someObject = {
employees:[
{name:"XYZ",age:30},
{name:"ABC",age:28},
]
}
I want to transform this data into below structure where name, age are as it is and description will be calculated based on name and age
{
name :
age :
description: //calculate based on name and age
},
{
name :
age :
description: //calculate based on name and age
}
Above structure will be typed to some Interface and this is ultimately returned from my Angular service
How can I do this using RxJS ?
Can anybody please help me as I am struggling with it
Ultimately , my Angular service will return data as above structure ?
EDIT :
Based on responses got , I tried below :
return this.http.get<any>(url).pipe(
map(data => data.employees),
map(employees =>{
values.map(employee =>{
console.log('individual value =',employee);
return{
employee,
description:employee.name + "" + employee.age
}
})
})
)
But when this Observable is subscribed , I am getting value as undefined.
Is it because the second map operator map(employees is not returning anything ?
How can I make it return object constructed from inner map ?
pipeand thenmapoperator to create new object containing description along with other fields?