I have a question that I need help with. After parsing a JSON object from an AJAX request, I obtained an object called usrobj.
console.log(usrobj.available[0]);
The usrobj.available is actually an array:
(2) [{…}, {…}]
0:{currency: "ETH", amount: "0.5"}
1:{currency: "BTC", amount: null}
length:2
__proto__:Array(0)
This resulted in a vardump like this:
{currency: "ETH", amount: "0.5"}
amount:"0.5"
currency:"ETH"
__proto__:Object
However, when I tried to loop through the array using the following code:
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...
I encountered an error message: 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)
If anyone could advise me on whether they are in different scopes and how to fix this issue, I would greatly appreciate it.