tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

use-includes-instead-of-indexOf.rst (499B)


      1 use-includes-instead-of-indexOf
      2 ===============================
      3 
      4 Use ``.includes`` instead of ``.indexOf`` to check if something is in an array
      5 or string.
      6 
      7 Examples of incorrect code for this rule:
      8 -----------------------------------------
      9 
     10 .. code-block:: js
     11 
     12    let a = foo.indexOf(bar) >= 0;
     13    let a = foo.indexOf(bar) == -1;
     14 
     15 Examples of correct code for this rule:
     16 ---------------------------------------
     17 
     18 .. code-block:: js
     19 
     20    let a = foo.includes(bar);
     21    let a = foo.indexOf(bar) > 0;