This time I will bring you the judgment of the value that exists in the array, and what are the precautions for judging the value that exists in the array. The following is a practical case, let's take a look.
<!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:
Operation Angularjs cross-domain setting whitelist
How to use Angular data binding mechanism
The above is the detailed content of Determine the value existing in the array. For more information, please follow other related articles on the PHP Chinese website!