My API returns this response:
{"__v":0,"short":"8xdn4a5k","_id":"5404db5ac27408f20440babd","branches":[{"version":1,"code":""}],"ext":"js","language":"javascript"}
This works:
console.log(response.short);
but this produces undefined:
console.log(response.branches.version);
How come?
The branches property of response is an array:
"branches":[{"version":1,"code":""}]
So, you have to access the first element of branches (which is the object you're looking for) to get the version property:
response.branches[0].version
Well, branches has no nodes that can be reach by it's name, only an array, so you can't get it by a name (which doesn't have) , you'll have to do:
console.log(response.branches[0].version);
Indexed and Associative arrays are different.