0

Right now I have this going where if water or ocean is included in this.state then do this:

{this.state.ticket.includes('water') || this.state.ticket.includes('ocean') ?
// do something
:
// do something else
}

Is there a simplier way to put all the strings in .includes instead of repeating the same or code? Thank you!

Laney Williams
  • 573
  • 3
  • 13
  • 34
  • Possible duplicate of [multiple conditions for JavaScript .includes() method](https://stackoverflow.com/questions/37896484/multiple-conditions-for-javascript-includes-method) – Soroush Chehresa Sep 23 '18 at 04:13

1 Answers1

1

Try the below see if it works:

  1. make an array of text you want to check.
  2. then use .some to check each element in the text array is included in the state.
var textArray = ['1', '2'];        
var state ='1';

var check = function(element) {return state.includes(element);}         
console.log(textArray.some(check));
wp78de
  • 18,207
  • 7
  • 43
  • 71
Fan
  • 28
  • 4