Amar Singh
Amar Singh

Reputation: 5622

Filter an array with two comparisions

I am filtering an array using .filter, for example:

stack_wr = stack_wr.filter(function(obj2) {
    return obj2.class != sec__id;
});

The above code works perfectly as I require. My question is can I filter using two comparisons or return statements? One with obj2.class != sec__id which I have already done and again with obj2.type != whatever_value or do I have to filter two times like the way I have done below:

stack_wr = stack_wr.filter(function(obj2) {
    return obj2.class != sec__id;
});

stack_wr = stack_wr.filter(function(obj2) {
    return obj2.type != whatever_value;
});

Upvotes: 1

Views: 31

Answers (1)

Mohamed-Yousef
Mohamed-Yousef

Reputation: 24001

did you try

stack_wr.filter(function(){
   return this.className !== 'email' && this.type !== 'password';
});

Simple Demo

Upvotes: 1

Related Questions