1

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.

2 Answers 2

3

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']

Documentation

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Property_accessors

Sign up to request clarification or add additional context in comments.

Comments

0

try to change to

.then((response) => response.json())
.then((responseJson) => {
    LINK = responseJson.links["datasets-pollencheck_apiaries"];

})

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.