Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • 25
    This doesn't work for old browsers (like IE < 9). There's a jQuery function for this: api.jquery.com/jQuery.inArray Commented Oct 5, 2012 at 14:42
  • 5
    A faster way is to flip the bit wise if(!!~blockedTile.indexOf('118)) this method will always return true if the result > -1 and false if result === -1 Commented Nov 5, 2012 at 19:01
  • 14
    @bm_i Which faster? Faster to type? Commented Oct 2, 2013 at 20:01
  • 3
    indexOf() can also be applied on literal arrays, e.g. if (-1 == [84, 116].indexOf(event.keyCode)). Tested on Chrome 37.0.2062.122. Commented Sep 24, 2014 at 16:58
  • 2
    fwiw I always use indexOf(…) >= 0. makes no difference and i forget where i picked it up as a habit Commented Mar 8, 2016 at 12:10