i have a object that i want to update the 'marketBuyPrice' and 'marketSellPrice' entries for using data from a fetch call as follows:
//The object
const ores = {
Hemorphite :{ name: 'Hemorphite', marketRef: '1231', marketBuyPrice: '', marketSellPrice: ''},
Veldspar :{ name: 'Veldspar', marketRef: '1230', marketBuyPrice: '', marketSellPrice: ''},
};
//The fetch call
function getMarketPrices(oreType, id) {
var marketUrl = 'https://api.evemarketer.com/ec/marketstat?typeid='+id+'&usesystem=30000142';
fetch(marketUrl)
.then(response => response.text())
.then(str => (new DOMParser()).parseFromString(str, "text/xml"))
.then(data => {
var buyPrice = data.getElementsByTagName("percentile")[0].childNodes[0].nodeValue;
var sellPrice = data.getElementsByTagName("percentile")[1].childNodes[0].nodeValue;
//This is where the buy / sell prices get updated
ores[oreType].marketBuyPrice = buyPrice;
ores[oreType].marketSellPrice = sellPrice;
})
}
This works if i then view the entire array using:
console.log(ores);
Which returns:
{Hemorphite: {…}, Veldspar: {…}}
Hemorphite: {name: "Hemorphite", marketRef: "1231", marketBuyPrice: "1004.87", marketSellPrice: "1678.93"}
Veldspar: {name: "Veldspar", marketRef: "1230", marketBuyPrice: "12.00", marketSellPrice: "20.70"}
However if i try to view the specific updated entry:
console.log(ores[oreType].marketBuyPrice);
it returns it as empty as if it hasnt been updated yet when viewing the entire object as above it shows it as updated.
Could anyone offer any insight as to why this may be please.
Many thanks
//Update
const ores = {
Hemorphite :{ name: 'Hemorphite', marketRef: '1231', marketBuyPrice: '', marketSellPrice: '', refines: {isogen: '2.4', nocxium: '9'} },
Veldspar :{ name: 'Veldspar', marketRef: '1230', marketBuyPrice: '', marketSellPrice: ''},
};
const minerals = {
Hemorphite :{ name: 'Hemorphite', marketRef: '1231', marketBuyPrice: '', marketSellPrice: '',},
Veldspar :{ name: 'Veldspar', marketRef: '1230', marketBuyPrice: '', marketSellPrice: '',},
};
function getMarketPrices(oreType, id) {
var marketUrl = 'https://api.evemarketer.com/ec/marketstat?typeid='+id+'&usesystem=30000142';
fetch(marketUrl)
.then(response => response.text())
.then(str => (new DOMParser()).parseFromString(str, "text/xml"))
.then(data => {
var buyPrice = data.getElementsByTagName("percentile")[0].childNodes[0].nodeValue;
var sellPrice = data.getElementsByTagName("percentile")[1].childNodes[0].nodeValue;
ores[oreType].marketBuyPrice = buyPrice;
ores[oreType].marketSellPrice = sellPrice;
})
}
console.log(ores);
console.log((ores['Veldspar'].marketBuyPrice));
