I have this piece of code in an angular controller that looks like so:
for (var obj in $scope.items) {
obj.done = false;
}
Here's how my $scope.items
look:
$scope.items = [
{
name: "Task #1",
done: false
},
{
name: "Task #2",
done: false
}
];
It seems weird to me that my for loop actually doesn't work. obj
isn't an object within the loop. I tried to do a console.log
of the obj
variable and it prints out the index of the array $scope.items
. Why is this so? Since this is a foreach
loop, shouldn't obj
be each of the objects inside $scope.items
?