Home > Mobile >  How to repeat the same short code in JavaScript
How to repeat the same short code in JavaScript

Time:11-03

   if (
     titleValue.toUpperCase().indexOf(filter) > -1 ||
     sepiValue.toUpperCase().indexOf(filter) > -1 ||
     discValue.toUpperCase().indexOf(filter) > -1 ||
     dateValue.toUpperCase().indexOf(filter) > -1
   ) {
     movieCard[i].style.display = "";
   } else {
     movieCard[i].style.display = "none";
   }

** I want to short this code at code statement ||**

I want to use dry consent in this code, please anyone help?

CodePudding user response:

What do you think about:

const hasFilter = [titleValue, sepiValue, discValue, dateValue]
  .find(item => item.toUpperCase().indexOf(filter) > -1);

movieCard[i].style.display = hasFilter ? "" : "none";
  • Related