global test
global test

Reputation: 25

How to check all array equal to some value in angular js?

self.scope.savesectioneditmain = [self.scope.savesection2details,
                                  self.scope.editsection2,
                                  self.scope.savesection1details,
                                  self.scope.editsection1];

Based on above codes, I want to check all array value equal to true value.

if($.inArray(true, self.scope.savesectioneditmain) == 0)

I have tried $inArray, but $inArray checks only one condition, but I want to check all array value should be equal to true.

Upvotes: 0

Views: 2394

Answers (1)

Satpal
Satpal

Reputation: 133453

You can use Array.prototype.every()

The every() method tests whether all elements in the array pass the test implemented by the provided function.

if(self.scope.savesectioneditmain.every(x => x == true)){
   //All elements are true
}

Upvotes: 1

Related Questions