
Please show your love and support by sharing this post. The Javascript array. GitHub - kevlatus/polyfill-array-includes: This is a polyfill for. Similarly, in the following cases, () does a " strict equality comparison":Ĭonsole.log(.includes(2)) // trueĬonsole.log(.includes(4)) // falseĬonsole.log(.includes(+0)) // trueĬonsole.log(.includes(-0)) // trueĬonsole.log(.includes('foo')) // trueĬonsole.log(.includes('Foo')) // falseĬonsole.log(.includes('fo')) // false This is a polyfill for the method based on the code from MDN. This is the same as it would happen in a strict equals ( =) comparison: This means, for example, that a numeric string won't equal its integer counterpart: Other than that one exception, Same-Value-Zero algorithm and strict equality actually yield the same result. Suppose you have a simple array with 3 elements: const arr 'A', 'B', 'C' To determine whether arr contains the string 'B', you can use Arrayincludes () or ArrayindexOf (). I needed a bit of JavaScript that would look at an array of objects and see if it contained an element that. For example:Ĭonsole.log(.includes(NaN)) // true Given a JavaScript array, there are two built-in array methods you can use to determine whether the array contains a given element. Array Deep Contains Function for JavaScript. However, in a stricter sense, the " strict equality comparison" differs from the ( Same-Value-Zero) algorithm () method uses under the hood in terms of NaN equality. You could technically say that the JavaScript () method does a strict equality comparison of values. El método includes () es intencionalmente genérico.
