Filter API Response

Howdy,
I need help transforming the response from an API call.
Looking to be able to transform the data to "displayName": "John Smith" & "value":"(817)-111-1111"

{
"connections": [
{
"resourceName": "people/c8521814946305147275",
"etag": "%EgcBAgsuNz0/GgQBAgUHIgx4cDZvRnRlcWlxWT0=",
"names": [
{
"metadata": {
"primary": true,
"source": {
"type": "CONTACT",
"id": "7643918b0c22018b"
}
},
"displayName": "John Smith",
"familyName": "John",
"givenName": "Smith",
"displayNameLastFirst": "Smith, John",
"unstructuredName": "John Smith"
}
],
"phoneNumbers": [
{
"metadata": {
"primary": true,
"source": {
"type": "CONTACT",
"id": "7643918b0c22018b"
}
},
"value": "(817) 111-1111",
"canonicalForm": "+18171111111",
"type": "work",
"formattedType": "Work"
}
]
},
{
"resourceName": "people/c5805446273449066176",
"etag": "%EgcBAgsuNz0/GgQBAgUHIgxsVVpYeHI3Mk15WT0=",
"names": [
{
"metadata": {
"primary": true,
"source": {
"type": "CONTACT",
"id": "509116a08b8bfec0"
}
},
"displayName": "Alan Smith",
"familyName": "Alan",
"givenName": "Smith",
"displayNameLastFirst": "Smith, Alan",
"unstructuredName": "Alan Smith"
}
],
"phoneNumbers": [
{
"metadata": {
"primary": true,
"source": {
"type": "CONTACT",
"id": "509116a08b8bfec0"
}
},
"value": "+1 214-111-1111",
"canonicalForm": "+12141111111",
"type": "mobile",
"formattedType": "Mobile"
},
{
"metadata": {
"source": {
"type": "CONTACT",
"id": "509116a08b8bfec0"
}
},
"value": "+1 469-111-1111",
"canonicalForm": "+14691111111",
"type": "mobile",
"formattedType": "Mobile"
}
]
}
],
"nextPageToken": "GgYKAghkEAI",
"totalPeople": 208,
"totalItems": 208
}

The API call is yourQuery:

yourQuery.data.connections should be your array of people. Each object of the array has properties; you are interested in the names and phoneNumbers properties.

The JS Query you want to build should go through the array and extract these properties into a new object array for use in your app. There are a few ways to do this in your code, a verbose example below being a loop:

let newResults = [];
let data = yourQuery.data;
for(let i = 0; i<data.connections.length; i++){
newResults.push({
    "displayName": data.connections[i].names[0].displayName,
    "value": data.connections[i].phoneNumbers[0].value
    });
}
return newResults;

Example in app (with different approaches for converting result data):

If people have multiple names or numbers in their data (names and phoneNumbers are arrays) you'd have to loop through those as well to add them to the return array.