Reputation: 137
i currently have an array of objects i use to generate html checkboxes (ng-repeat). All those objects have an x.checked = true / false attribute. How can i set this x.checked = false for all objects at once?
Right now i use a simple for loop.
for(var i = 0; i < array.length; i++) {
array[i].checked = false;
}
Does Angular have a faster or shorter way of doing this?
Thanks!
Upvotes: 3
Views: 799
Reputation: 153
Or you could use Array.forEach similar syntax to angular.forEach but I think it will be faster.
items.forEach(function (item, index, array) {
item.checked = false;
});
Upvotes: 1
Reputation: 51
Yes , You can use angular.forEach
for this, Like so:
angular.forEach(array, function (item) {item.checked = false;}
Upvotes: 1
Reputation: 10849
There is no way to do it per se, no matter how you write it, you will never do it all at once, it will at best be a shorthand for what your wrote above.
Upvotes: 2