summaryrefslogtreecommitdiffstats
path: root/docs/code-quality/lint/linters/eslint-plugin-mozilla/use-includes-instead-of-indexOf.rst
blob: bb65ebea2ceddce4b6e885d4aabb24bc65f7407d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
use-includes-instead-of-indexOf
===============================

Use ``.includes`` instead of ``.indexOf`` to check if something is in an array
or string.

Examples of incorrect code for this rule:
-----------------------------------------

.. code-block:: js

    let a = foo.indexOf(bar) >= 0;
    let a = foo.indexOf(bar) == -1;

Examples of correct code for this rule:
---------------------------------------

.. code-block:: js

    let a = foo.includes(bar);
    let a = foo.indexOf(bar) > 0;