I need to return in my fetch promise a JSON object which contains all my data. The issue is I don't know what the object name is. What I do know is that there will always be one object.
Here is me example code where I get what I need knowing the object name (in this case foo
return fetch(endPoint)
.then(res => res.json())
.then(res => res.foo)
.then(res => console.log(res))
My response would look like this
{
"foo": [
"bar1",
"bar2",
"bar3"
]
}
However my code would fail if this was the response:
{
"goo": [
"bar1",
"bar2",
"bar3"
]
}
How can I ensure my code always works no matter what the object is called?