Sneaky Wombat
Sneaky Wombat

Reputation: 1848

breaking out of _.filter()

_.filter(this.pluck(key),function(item){
    return item ? value.toLowerCase() === item.toLowerCase() : false;
  });

Is there a way to stop the filter iteration if the return value of the callback is true?

Upvotes: 3

Views: 1686

Answers (2)

Tino Rüb
Tino Rüb

Reputation: 809

Such worse - but the best approach seems to be to handle your DS like (or convert to) an array and iterate with a for-loop or equivalent with a break; conditon.

Please Downvote AND awnser the quest. if this is wrong. ;)

Upvotes: 1

Sneaky Wombat
Sneaky Wombat

Reputation: 1848

I found out this can be done with any (aka some):

_.any(this.pluck(key),function(item){
        return item ? value.toLowerCase() === item.toLowerCase() : false;
      });

Upvotes: 2

Related Questions