MCPcopy Create free account
hub / github.com/ampproject/amphtml / includes

Function includes

src/polyfills/array-includes.js:9–24  ·  view source on GitHub ↗

* Returns true if the element is in the array and false otherwise. * * @param {*} value * @param {number=} opt_fromIndex * @return {boolean} * @this {Array}

(value, opt_fromIndex)

Source from the content-addressed store, hash-verified

7 * @this {Array}
8 */
9function includes(value, opt_fromIndex) {
10 const fromIndex = opt_fromIndex || 0;
11 // eslint-disable-next-line local/no-invalid-this
12 const len = this.length;
13 let i = fromIndex >= 0 ? fromIndex : Math.max(len + fromIndex, 0);
14 for (; i < len; i++) {
15 // eslint-disable-next-line local/no-invalid-this
16 const other = this[i];
17 // If value has been found OR (value is NaN AND other is NaN)
18 /*eslint "no-self-compare": 0*/
19 if (other === value || (value !== value && other !== other)) {
20 return true;
21 }
22 }
23 return false;
24}
25
26/**
27 * Sets the Array.contains polyfill if it does not exist.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected