Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Current browsers have <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes#Browser_compatibility" rel="noreferrer"><code>Array#includes</code></a>, which does <em>exactly</em> that, <a href="https://kangax.github.io/compat-table/es2016plus/#test-Array.prototype.includes" rel="noreferrer">is widely supported</a>, and has a <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes#Polyfill" rel="noreferrer">polyfill</a> for older browsers.</p> <pre><code>&gt; ['joe', 'jane', 'mary'].includes('jane'); true </code></pre> <p>You can also use <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf" rel="noreferrer"><code>Array#indexOf</code></a>, which is less direct, but doesn't require Polyfills for out of date browsers.</p> <p>jQuery offers <a href="http://api.jquery.com/jquery.inarray/" rel="noreferrer"><code>$.inArray</code></a>, which is functionally equivalent to <code>Array#indexOf</code>.</p> <p><a href="http://underscorejs.org/#" rel="noreferrer">underscore.js</a>, a JavaScript utility library, offers <a href="http://underscorejs.org/#contains" rel="noreferrer"><code>_.contains(list, value)</code></a>, alias <code>_.include(list, value)</code>, both of which use <a href="http://underscorejs.org/#indexOf" rel="noreferrer">indexOf</a> internally if passed a JavaScript array.</p> <p>Some other frameworks offer similar methods:</p> <ul> <li>Dojo Toolkit: <a href="http://dojotoolkit.org/reference-guide/dojo/indexOf.html" rel="noreferrer"><code>dojo.indexOf(array, value, [fromIndex, findLast])</code></a></li> <li>Prototype: <a href="http://api.prototypejs.org/language/Array/prototype/indexOf/" rel="noreferrer"><code>array.indexOf(value)</code></a></li> <li>MooTools: <a href="https://mootools.net/core/docs/1.6.0/Types/Array#Array:indexOf" rel="noreferrer"><code>array.indexOf(value)</code></a></li> <li>MochiKit: <a href="http://mochi.github.io/mochikit/doc/html/MochiKit/Base.html#fn-findvalue" rel="noreferrer"><code>findValue(array, value)</code></a></li> <li>MS Ajax: <a href="http://www.asp.net/ajaxlibrary/Reference.Array-indexOf-Function.ashx" rel="noreferrer"><code>array.indexOf(value)</code></a></li> <li>Ext: <a href="http://docs.sencha.com/extjs/4.0.0/#/api/Ext.Array-method-contains" rel="noreferrer"><code>Ext.Array.contains(array, value)</code></a></li> <li>Lodash: <a href="https://lodash.com/docs#includes" rel="noreferrer"><code>_.includes(array, value, [from])</code></a> (is <code>_.contains</code> prior 4.0.0)</li> <li>ECMAScript 2016: <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/includes" rel="noreferrer"><code>array.includes(value)</code></a></li> </ul> <p>Notice that some frameworks implement this as a function, while others add the function to the array prototype.</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