Skip to content

Commit 9959d69

Browse files
baamenabarkswedberg
authored andcommitted
jQuery.inArray(): Note that inArray campares values strictly. Closes jquery#470
1 parent c462647 commit 9959d69

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

entries/jQuery.inArray.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@
1616
<desc>Search for a specified value within an array and return its index (or -1 if not found).</desc>
1717
<longdesc>
1818
<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>
19-
<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>
19+
<p>Because JavaScript treats 0 as loosely equal to false (i.e. 0 == false, but 0 !== false), to check for the presence of <code>value</code> within <code>array</code>, you need to check if it's not equal to (or greater than) -1.</p>
20+
<p>The comparison between values is strict. The following will return <code>-1</code> (not found) because a number is being searched in an array of strings:</p>
21+
<pre><code>$.inArray( 5 + 5, [ "8", "9", "10", 10 + "" ] );</code></pre>
2022
</longdesc>
2123
<example>
2224
<desc>Report the index of some elements in the array.</desc>

0 commit comments

Comments
 (0)