This time I will bring you jQueryWhether there is a specified value in the array and determine whether there is a specified value in the jQuery arrayWhat are the precautions, as follows This is a practical case, let’s take a look at it.
<!DOCTYPE> <html> <head> <title>jquery判断值是否存在于数组中</title> <meta charset="utf-8"> </head> <body> <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script> <script> //参数第一个为数组,第二个为需要判断是否存在于数组中的值 function isInArray(arr,val){ var str = ","+arr.join(",")+","; if(str.indexOf(","+val+",") != "-1"){ //该数存在于数组中 arr.splice($.inArray(val,arr),1); //把该数从数组中删除 console.log(arr); }else{ //该数不存在于数组中 console.log("不存在"); } } var arr = [1,28,60,80,6]; isInArray(arr,28);//存在,删除元素28 isInArray(arr,18);//不存在,提示“不存在” </script> </body> </html>
Run results:
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website!
Recommended reading
How to make a non-empty judgment for el expression in js
Share the page and jump back to the homepage
The above is the detailed content of Whether the specified value exists in the jQuery array. For more information, please follow other related articles on the PHP Chinese website!