So I have a conundrum involving the following code:
$scope.getUserContact = function(data) {
var i;
for (i = 0; i < data.length; i += 1) {
$http({
method: 'GET',
url: [Removed]
}).then(function successCallback(response) {
alert(JSON.stringify(data));
alert(data.length);
alert(JSON.stringify(data[i]));
...
}, function errorCallback(response) {
});
}
}
First line spits out:
[
{
"listingId":"String",
...other Strings and ints ...
}
]
Basically, it spits out an array consisting of one object.
Second line spits out
1
As expected, the length of the array is 1.
Third line spits out
undefined
I just don't understand how indexing an array suddenly results in undefined
instead of giving me the object at the index.
It may be notable that data
is a parameter to a function.
Any help? I assume it's either a stupid error on my part or some strange and unknown behavior from the depths of JavaScript.