I got a question here. I got an object (usrobj) after parsing a JSON object from ajax
console.log(usrobj.available[0]);
where usrobj.available is an array
(2) [{…}, {…}]
0:{currency: "ETH", amount: "0.5"}
1:{currency: "BTC", amount: null}
length:2
__proto__:Array(0)
This results a vardump like this
{currency: "ETH", amount: "0.5"}
amount:"0.5"
currency:"ETH"
__proto__:Object
However when I try to loop through the
for(i = 0; i < usrobj.available.length; ++i) {
$('#assets-table').append('<tr>\
<td>'+usrobj.available[i].currency+'</td>\
<td>Available: '+usrobj.available[i].amount+' (Frozen: '+usrobj.frozen[i].amount+')<br /></td>\
...removed for brevity...
Uncaught TypeError: Cannot read property '0' of undefined
at Object.success (readAssets.js:22)
at i (jquery-3.2.1.min.js:2)
at Object.fireWith [as resolveWith] (jquery-3.2.1.min.js:2)
at A (jquery-3.2.1.min.js:4)
at XMLHttpRequest.<anonymous> (jquery-3.2.1.min.js:4)
could anyone please advise me if they are in different scope? and how do i fix this problem?