Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a list of current possibilities:</p> <p><strong>1. (ES6) <code>includes</code></strong>—<a href="https://stackoverflow.com/a/14193950/2689455">go to answer</a></p> <pre><code>var string = "foo", substring = "oo"; string.includes(substring); </code></pre> <p><strong>2. ES5 and older <code>indexOf</code></strong></p> <pre><code>var string = "foo", substring = "oo"; string.indexOf(substring) !== -1; </code></pre> <p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf" rel="noreferrer"><code>String.prototype.indexOf</code></a> returns the position of the string in the other string. If not found, it will return <code>-1</code>.</p> <p><strong>3. <code>search</code></strong>—<a href="https://stackoverflow.com/a/2385801/2689455">go to answer</a></p> <pre><code>var string = "foo", expr = /oo/; string.search(expr); </code></pre> <p><strong>4. lodash includes</strong>—<a href="https://stackoverflow.com/a/20575032/2689455">go to answer</a></p> <pre><code>var string = "foo", substring = "oo"; _.includes(string, substring); </code></pre> <p><strong>5. RegExp</strong>—<a href="https://stackoverflow.com/a/1789980/2689455">go to answer</a></p> <pre><code>var string = "foo", expr = /oo/; // no quotes here expr.test(string); </code></pre> <p><strong>6. Match</strong>—<a href="https://stackoverflow.com/a/12652006/2689455">go to answer</a></p> <pre><code>var string = "foo", expr = /oo/; string.match(expr); </code></pre> <hr> <p><a href="http://jsben.ch/#/RVYk7" rel="noreferrer">Performance tests</a> are showing that <code>indexOf</code> might be the best choice, if it comes to a point where speed matters.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload