How do I get to, Value, Editions, Price, Average?
My non working code:
.append(th.clone().text(value.editions[0].price[1].average))
The JSON layout:
{
"name": "About Face",
"id": "about-face",
"url": "https://api.deckbrew.com/mtg/cards/about-face",
"store_url": "http://store.tcgplayer.com/magic/urzas-legacy/about-face",
"types": [
"instant"
],
"colors": [
"red"
],
"cmc": 1,
"cost": "{R}",
"text": "Switch target creature's power and toughness until end of turn.",
"formats": {
"commander": "legal",
"legacy": "legal",
"vintage": "legal"
},
"editions": [
{
"set": "Urza's Legacy",
"price": {
"low": 89,
"average": 154,
"high": 198
},
"url": "https://api.deckbrew.com/mtg/cards?multiverseid=12414",
}
]
}
My Fiddle can be found here:
1 Answer 1
You should use
.append(th.clone().text(value.editions[0].price.average))
Remove [0] from price, since price is an object not an array.
answered Jun 18, 2014 at 2:37
ilonabudapesti
9031 gold badge6 silver badges9 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
Patrick2Go
update, it worked with high and low, just not average... not sure if it has anything to do with those being the first and last within 'price'.
ilonabudapesti
@user3730047 If it worked with high and low then the property access worked correctly so please upvote the answer. As for 'average' I suspect there is a typo on either end which is why you can't get the value. Alternatively the function calculating the average is not functioning correctly and you aren't getting an average value correctly. Please post another question on that with details on the average calculation. Thanks.
Patrick2Go
Looks like average is actually median, so you are correct.
lang-js
value.editions[0].price.average- price is an object not an array so there is no need to use an index based access