the following is a function in an angular controller. "alert (coffee.brand)", or any other part of the array, prints "undefined," which obviously it isn't. The weird part is, undefined prints the correct number of times in the for loop, so it knows the array is populated, it just can't seem to read the data. thoughts? Thanks in advance!
$scope.activate = function(id){
$scope.coffees =
[
{'id': 1,
'brand': 'Folgers',
'name': 'Regular',
'country': 'America',
'reviews': [
{'rating': 3,
'comment': "gross",
'reviewer': "James"
}
]
},
{'id': 2,
'brand': 'Starbucks',
'name': 'Mocha',
'country': 'America',
'reviews': [
{'rating': 7,
'comment': 'insane!',
'reviewer': 'Bob'
},
{'rating': 5,
'comment': 'solid...',
'reviewer': 'Joe'
}
]
}
];
for (coffee in $scope.coffees){
alert (coffee.brand);
if (coffee.id == id){
$scope.currCoffee = coffee;
alert("here")
alert ($scope.currCoffee.id);
}
}
};