Search code examples
javascripttypescriptlodash

How do I use lodash to check every item in a collection except those that dont meet my condition?


let allChecked = _.every(this.collection, this.checked);

I have this existing code that returns true if every item in the collection has true for the checked property. I want to modify it so that instead of iterating on every item in the collection, only items that do not have true on another property are iterated on. I.e., there is another property called disabled for the items in the collection. If this property is set to true, I would like to ignore those items completely from this _.every() check.


Solution

  • You could just call _.reject on the this.collection to remove any items that have true on the specified property in the collection.

    An example would be like _.every(_.reject(this.collection, 'disabled'), this.checked)