Easiest way to handling indexOf

Lets create a function that allow us to if string is available in array with this shortcode

function checkStringInArray(arrayItem, stringItem) {
  return !!~arrayItem.indexOf(stringItem);

using tilde operator will flip the bits in its operand. which is similar to


then use !! to convert this into boolen, this is easiest way to check indexOf and its more readable than …

  arrayItem.indexOf(stringItem) > -1