Reputation: 11
My fetch returns this promise which works for other fields in the API but I need to save the value for a field within that has the name "datasets-pollencheck_apiaries" however react-native inteprets the "-" as something else and I can't access this field, and continually get the error that says "Can't find variable: pollencheck_apiaries"
.then((response) => response.json())
.then((responseJson) => {
LINK = responseJson.links.datasets-pollencheck_apiaries;
})
Any insight would be much appreciated.
Upvotes: 1
Views: 90
Reputation: 41
This is because JavaScript thinks you're trying to do a math operation. You can also access object properties with bracket notation.
You should try this:
LINK = responseJson.links['datasets-pollencheck_apiaries']
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors
Upvotes: 3
Reputation: 69
try to change to
.then((response) => response.json())
.then((responseJson) => {
LINK = responseJson.links["datasets-pollencheck_apiaries"];
})
Upvotes: 0