Проверьте, resp/resp.data
является нулевым или нет.Если resp/resp.data
равно нулю, в индексе нет ничего 0
.
ws.onmessage = function (msg){
var resp = JSON.parse(msg.data);
console.log('Data : ' + data);
console.log('resp: ' + resp);
var price;
if(resp && resp.data){
price = resp.data[0].price; // can not read property 0 of undefined :/
}
console.log('Price is : ' + price);
//document.getElementById('btcPrice').value = price;
};