I need to know if there's a fancy way to return an array of strings created by the properties of an array of objects. The property of those objects it's also an array.
E.g Data:
[
{
servicesOffered: ["x","Y"]
},
{
servicesOffered: ["z","w"]
}
]
I tried to be fancy using the spread operator but doesn't work. I know I can iterate again the array of servicesOffered, but I don't know if there's a fancier or better way to do this.
Code:
getServices(results: Business[]): string[] {
return results.map(({ servicesOffered }) => {
const t = servicesOffered;
return ...t;
});
}
Expected Output
["x","Y","z","w"]