0

code snippet of unirest

As you can see above, arrayIndexOf refers to a function. When invoking the arrayIndexOf function, is it necessary to put "~" before "arrayIndexOf"? I try to change "~arrayIndexOf(value, field)" to "arrayIndexOf(value, field)". And it works as the same? Is there anything I miss?

quan lili
  • 109
  • 6

1 Answers1

0

In JavaScript, the tilde ~ Bitwise NOT operator is commonly used right before an indexOf() to do a boolean check (truthy/falsy) on a string. On its own, indexOf() returns the index number of a String object passed in. So if -1 is returned it will be turned into 0 which is falsy.

Source: https://wsvincent.com/javascript-tilde/

user9385381
  • 252
  • 3
  • 10