Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6213

extract values from an object with forEach

$
0
0

I run a graphql query and obtain data (data.personalPlaces), an object that looks like this:

nodes: (4) [{…}, {…}, {…}, {…}]

where each node is like this:

0:customisedName: "HomeOfBestFriendAlice"id: 1placeName: "Husbrok 1, 26127 Oldenburg, Deutschland"center: "Zes"__typename: "FavouritePlace"__proto__: Object

I want to iterate through all nodes such that I can make an array out of it

  favouriteLocations: [    {      name: 'Zu Hause',      street: 'Müllersweg',    },    {      name: 'Büro',      street: 'Philipp-Reis-Gang',    },    {      name: 'KaffeeHaus',      street: 'Cloppenburgerstr.',    },  ],

where name is the customisedName and street is the placeName from my original data. How can I achieve this?

Data shape:

{"data": {"personalFavouritePlaces": {"nodes": [        {"placeName": "Paris, France"        },      ]    }  }}

Viewing all articles
Browse latest Browse all 6213

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>