2017-01-02 23 views
0
self.scope.savesectioneditmain = [self.scope.savesection2details, 
            self.scope.editsection2, 
            self.scope.savesection1details, 
            self.scope.editsection1]; 

根據上面的代碼,我想檢查所有數組值等於true值。如何檢查所有數組等於角js中的某個值?

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

我已經試過$inArray,但$inArray只檢查一個條件,但我要檢查所有的數組值應等於true

+0

你想檢查實際數組中的屬性?它是否包含一些對象的數組?或一些字符串?我一直在困惑。 – digit

+0

字符串true或false,我的數組包含true或false。 –

回答

1

可以使用Array.prototype.every()

every()方法測試所述陣列中的所有元素是否通過由提供的功能來實現的測試。

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

Thanq這麼多工作正常。 –

相關問題