I've got the following code:
function valor_actual(moneda) {
var url="https://poloniex.com/public?command=returnTicker";
var response = UrlFetchApp.fetch(url);
var dataAll = JSON.parse(response.getContentText());
var dataSet = dataAll;
var pair= "BTC_"+moneda
return dataSet.pair.last;
}
This code of couse is not working..
The moneda variable could have different values, for example, "VTC" or "AUR" or .... What i need is if moneda="AUR" return dataSet.BTC_AUR.last property and if moneda="SC" return dataSet.BTC_SC.last property, etc...
Regards,
1 Answer 1
Referring to these questions: How to convert string as object's field name in javascript ; Convert string value to object property name
Try changing your last line to:
dataSet[pair].last;
As a side note, based off the code you have given the line:
var dataSet = dataAll;
is redundant. The names lead me to believe that dataSet is meant to be a subset of dataAll but as written dataSet is just a copy of dataAll. So your code can be simplified to:
function valor_actual(moneda) {
var url="https://poloniex.com/public?command=returnTicker";
var response = UrlFetchApp.fetch(url);
var dataAll = JSON.parse(response.getContentText());
var pair= "BTC_"+moneda
return dataAll[pair].last;
}
Comments
Explore related questions
See similar questions with these tags.