I have an api call to get NFL spreads. Here is the json object:
[{"id": "d5b75a02ec389dcad39c351b640054a6",
"sport_key": "americanfootball_nfl",
"sport_title": "NFL",
"commence_time": "2021-09-19T17:00:00Z",
"home_team": "Miami Dolphins",
"away_team": "Buffalo Bills",
"bookmakers": [{"key": "fanduel",
"title": "FanDuel",
"last_update": "2021-09-19T01:42:23Z",
"markets": [{"key": "spreads",
"outcomes": [{"name": "Buffalo Bills",
"price": -106,
"point": -3.5},
{"name": "Miami Dolphins",
"price": -114,
"point": 3.5}]}]},
So I’m able to access everything using
getSpreads()
.then(
data => {
$w("#home").text = data.home_team;
});
This is working fine, it returns ‘Miami Dolphins’, but if I try to return the spread like this:
getSpreads()
.then(
data => {
$w("#home").text = data.home_team;
$w("#homeSpread").text = "" + data.bookmakers[0].markets[0].outcomes[1].point;
});
It returns undefined. I can access the name with data.bookmakers[0].markets[0].outcomes[1].name (this returns ‘Miami Dolphins’) so I know I’m on the correct branch of the tree, but if I try and return the number value for the spread (-3.5) it returns ‘undefined’.
This API returns a Json object with all strings, except for the spread which isn’t in quotes, (“point”: -3.5) so I assume it’s a number. I’m guessing this is my issue?