I'm very beginner in coding. Please help me with this:
I need to add an attribute 'name' to my array.
I got each element separately but don't know how to add attribute "name" to it :/ is it possible ?
Working with graphql an TS, I got this:
"myTypes": [ "cat", "dog", "bird", "butterfly" ]
and I need to become it like this :
"myTypes": [ {name: "cat"}, {name:"dog"}, {name: "bird"}, {name: "butterfly"}]
My code:
const mydata = response.data.myTypes let names = Array.from(mydata).forEach((element: any) => console.log(element))
thanks for your help !
mydata.map()to change the strings into objects.myData.map(e=>{return {name: e}})or similar.mydatashould already an array soArray.from(mydata)is unnecessary. Have a look atArray.prototype.map().