

indexOf (.) > 0 and includes (.) both return true if the given argument is present in the array. I would settle for this as a method covering most bases, simply stringify then test. some (.) checks each element of the array against a test function and returns true if any element of the array passes the test function, otherwise, it returns false. Please show your love and support by sharing this post.The thing is, anyone using anything that does not support HTML5 is an out of date browser (and yes I am aware that Mozilla are dragging its knuckles on this one) and in real terms, while it is nice to support these old browsers, the actual usage of them is declining to levels where support in terms of cost, benefits, time and effort in maintaining that code outweighs the perceived benefits for a very small browser user group. It is used to check array contains a value for a boolean. (Array): Returns the new array of filtered values. This tutorial covers a new method includes introduced in the Array class of ES7, ES2016 javascript. 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 iteratee.identity (Function): The iteratee invoked per element. 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. For example:Ĭonsole.log(.includes(NaN)) // true 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.
