Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular how to edit all elements in an array at ones

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!

like image 676
Bas Van Den Heuvel Avatar asked Feb 13 '26 02:02

Bas Van Den Heuvel


2 Answers

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.

like image 117
axelduch Avatar answered Feb 14 '26 15:02

axelduch


Yes , You can use angular.forEach for this, Like so:

angular.forEach(array, function (item) {item.checked = false;}
like image 41
Rajesh Kumar Maurya Avatar answered Feb 14 '26 16:02

Rajesh Kumar Maurya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!