Home > Article > Web Front-end > How to determine whether a value is in an array in jquery
In jquery, you can use the inArray() method to determine whether the value is in the array. The syntax is "$.inArray(value,array)"; if the specified value is in the array, it will return the value in the array. The subscript (index) of , if not, returns "-1".
The operating environment of this tutorial: windows7 system, jquery1.10.0 version, Dell G3 computer.
jquery determines whether the value is in the array
In jquery, you can use the inArray() method to determine whether the value is in the array.
$.inArray() function is used to find the specified value in the array and return its index value (if not found, it returns -1).
Using this feature, we can use the $.inArray() function to find the specified value in the array and see if -1 is returned to determine whether the value is in the array.
Implementation code:
<script src="js/jquery-1.10.0.min.js"></script> <script> var array=[1,2,3,4,5,6]; var value=2; var vlaue = $.inArray(value, array); if(value != -1) { console.log("指定值在数组中"); } else{ console.log("指定值不在数组中"); } </script>
Related video tutorial recommendations: jQuery tutorial (video)
The above is the detailed content of How to determine whether a value is in an array in jquery. For more information, please follow other related articles on the PHP Chinese website!