Jquery method to determine whether an element is in an array: Use the [$.inArray] method to determine whether the specified element is in the array. The [$.inArray()] function is used to find the specified value in the array and return it. Its index value, the syntax is [$.inArray( value, array[, from].
The operating environment of this tutorial: windows7 system, jquery3.2.1 version , Dell G3 computer.
Jquery method to determine whether an element is in an array:
In jquery, you can use the $.inArray
method to determine the specified element Whether it is in the array. $.inArray()
The function is used to find the specified value in the array and return its index value (if not found, it returns -1).
Syntax :
$.inArray( value, array [, fromIndex ] )
Parameters:
value
Any type of value used for lookup.
array Array
The type specifies the array to be searched.
fromIndex
Optional. The Number type specifies that the search starts from the specified index position of the array, the default is 0
var arry = [ "C#", "html", "css", "JavaScript" ]; var result= $.inArray("C#", arry);
Related free learning recommendations:
The above is the detailed content of How to determine if an element is in an array in jquery. For more information, please follow other related articles on the PHP Chinese website!