Home > Article > Web Front-end > How jQuery determines whether a value exists in an array
How jQuery determines whether a certain value exists in an array: 1. Use the array to determine one by one. The code is [if($.inArray('A',Arry)){'exists'}else{does not exist ]; 2. Use indeOf to judge, the code is [if (tabs.indeOf('incoming value')>-1].
This tutorial operation Environment: windows7 system, jquery3.2.1 version, this method is suitable for all brands of computers.
jQuery method to determine whether a certain value exists in an array:
Method 1 :
var Arry = [‘A’,‘B’,‘C’,‘D’,‘E’,‘F’]; if($.inArray(‘A’,Arry)){ ‘存在’ }else{ 不存在 }
Method 2:
var tabs = [‘A0’,‘B0’,‘C0’,‘D0’]; if (tabs.indeOf(‘传入值’)>-1){ 为真 }else{ 为假 }
Related learning recommendations: javascript learning tutorial
The above is the detailed content of How jQuery determines whether a value exists in an array. For more information, please follow other related articles on the PHP Chinese website!