From 69a9e55d6435657c5844f202ba7ee6998d19c8f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=2E=20Agust=EDn=20Amenabar=20L?= Date: Mon, 31 Mar 2014 15:16:02 -0400 Subject: [PATCH] .inArray method campares values strictly, adding comment about it --- entries/jQuery.inArray.xml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/entries/jQuery.inArray.xml b/entries/jQuery.inArray.xml index 16e43b60..360c5fbb 100644 --- a/entries/jQuery.inArray.xml +++ b/entries/jQuery.inArray.xml @@ -17,6 +17,9 @@

The $.inArray() method is similar to JavaScript's native .indexOf() method in that it returns -1 when it doesn't find a match. If the first element within the array matches value, $.inArray() returns 0.

Because JavaScript treats 0 as loosely equal to false (i.e. 0 == false, but 0 !== false), if we're checking for the presence of value within array, we need to check if it's not equal to (or greater than) -1.

+

The comparison between values is strict.

+
$.inArray( 5+5, ["8","9","10", 10+""] );
+

Will return -1 (not found) because a number is being searched in an array of strings.

Report the index of some elements in the array.