PHP has in_array () to determine whether an element exists in an array, but javascript does not. However, jQuery encapsulates the inArray () function to determine whether the element exists in an array: & amp; lt; script & amp; gt; varar
PHP has in_array () to determine whether an element exists in an array, but javascript does not. However, jQuery encapsulates the inArray () function to determine whether the element exists in an array:
Script var arr = [4, "Pete", 8, "John"]; var $ spans = $ ("span"); alert (jQuery. inArray ("John", arr); alert (jQuery. inArray (4, arr); alert (jQuery. inArray ("Karl", arr); // "Pete" is in the array, but the index is not 2 alert (jQuery. inArray ("Pete", arr, 2); script
In addition, jQuery also provides jQuery. isArray (obj) to check whether it is an array object, for example, $. isArray ([]) // returns true.