I am building the following code:
for(var i=0;i<datos.length;i++){
bittrex.getticker(datos[i].Currency,function(err, data){
if (err){
console.log('ERROR:', err);
return 'ERROR:'+ err;
} else {
if (data.message!='INVALID_MARKET') {
datos[i].LasValueBTC=data.result.Last;
} else {
datos[i].LasValueBTC='';
}
}
});
}
ok i get an error message: "Cannot set property 'LasValueBTC' of undefined". So i guessed that i variable is not being understood inside the callback function.. I tried without success:
for(var i=0;i<datos.length;i++){
bittrex.getticker(datos[i].Currency,(function(err, data){
if (err){
console.log('ERROR:', err);
return 'ERROR:'+ err;
} else {
if (data.message!='INVALID_MARKET') {
datos[i].LasValueBTC=data.result.Last;
} else {
datos[i].LasValueBTC='';
}
}
})(i)); //and also i tried }).bind(this,i));
}
How is this solved?
Regards,