Skip to content

.inArray method compares values strictly, adding a line about it #470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions entries/jQuery.inArray.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
<longdesc>
<p>The <code>$.inArray()</code> method is similar to JavaScript's native <code>.indexOf()</code> method in that it returns -1 when it doesn't find a match. If the first element within the array matches <code>value</code>, <code>$.inArray()</code> returns 0.</p>
<p>Because JavaScript treats 0 as loosely equal to false (i.e. 0 == false, but 0 !== false), if we're checking for the presence of <code>value</code> within <code>array</code>, we need to check if it's not equal to (or greater than) -1.</p>
<p>The comparison between values is strict.</p>
<pre><code>$.inArray( 5+5, ["8","9","10", 10+""] );</code></pre>
<p>Will return <code>-1</code> (not found) because a number is being searched in an array of strings.</p>
</longdesc>
<example>
<desc>Report the index of some elements in the array.</desc>
Expand Down