In jquery, you can use the "$.inArray()" method to query whether there is a value in the array. This method can search for the specified value in the array and return the index value of the specified value in the array. If the specified value does not exist in the array, "-1" is returned; syntax "$.inArray(value,array)".
Related recommendations: "jQuery Tutorial"
jquery determines whether the specified value exists in the array The value method $.inArray()
##$.inArray() method is used to search for the specified value in the array and returns the index value of the specified value in the array. If the array If the specified value does not exist, -1 is returned.Syntax
$.inArray( value, array [, fromIndex ] )
Example 1:Return the index value
var arrayStr = ['a','b','c']; alert($.inArray('a', arrayStr));
0
Example 2: Judge whether the specified value exists
var arrayStr = ['a','b','c']; if($.inArray('a',arrayStr) < 0){ alert('不存在'); }else{ alert('存在'); }
Programming Video! !
The above is the detailed content of How to check if there is a specified value in an array with jquery?. For more information, please follow other related articles on the PHP Chinese website!