Please show your love and support by sharing this post. 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 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. Syntax includes(keyword) includes(keyword, index) Parameter The function takes two parameters. Hence, it is best suited in if condition checks. For example:Ĭonsole.log(.includes(NaN)) // true El método includes () es intencionalmente genérico. includes () Function to Check if Array Contains Value in JavaScript The includes () function of JavaScript checks whether a given element is present in an array. 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.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |