When working with a fetch promise, I need to return a JSON object that contains all of my data. The challenge is that I am not sure what the object name will be. What I do know is that there will always be one object present.
Below is an example of my code where I am able to retrieve the necessary data when I know the object name (in this case, "foo"):
return fetch(endPoint)
.then(res => res.json())
.then(res => res.foo)
.then(res => console.log(res))
The response I expect would resemble this:
{
"foo": [
"bar1",
"bar2",
"bar3"
]
}
However, if the response looks like this:
{
"goo": [
"bar1",
"bar2",
"bar3"
]
}
My code would fail. How can I modify my code to ensure it will work regardless of the object name?