EDIT: here is a full gist of my code (API key of course removed): https://gist.github.com/tconroy/e52e0e7402face8f048e
I am having some issues with accessing objects{}
stored inside a JavaScript array[]
.
When I do console.dir(containerArray)
, I can see the 2 objects stored inside the array, like in the photo below:
However, when I perform
console.log(containerArray)
,
the output is just empty brackets []
.
When I try and access the array indexes via console.dir(containerArray[0]);
, the output is undefined
.
This is the code I am using to create the objects and put them into the array:
var key = String(decodeURIComponent(addr)),
obj = {};
obj[key] = json.data.weather;
containerArray.push(obj);
What am I doing wrong here? I need to be able to access each of the objects stored in the array and not sure what I'm doing wrong here.