Q:

The filter does not return anything even after match in Javascript

so I am trying use this Filter in one of my functions but the filter return empty array even though there are few matches .
code 
filteredCardList: function () {

  if (this.monthFilter.length > 0) {
    return this.cardList.filter((card) => {
      this.monthFilter.forEach(function (val) {
        if (val.toString() == card.months) {
          console.log('Matched')
          return true;
        } else {
          console.log('NoMatch')
          return false;
        }
      });
    })
  } else {
    return this.cardList
  }
}

Any ideas , most welcome
thanks

A:

Ok, assuming monthFilter is an array and you want to filter cardList by the values inside using an any sort of match, try using Array.prototype.some
filteredCardList: function () {
  if (this.monthFilter.length > 0) {
    return this.cardList.filter(card => {
      return this.monthFilter.some(val => {
        return val.toString() == card.months
      })
    })
  } else {
    return this.cardList
  }
}

Your problem was that your return true / return false was simply returning from the forEach callback and nothing was returned in the filter callback.

