欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

js判断字符是否存在数组中

程序员文章站 2022-04-14 16:13:38
~~~javascript //检测某个字符是否在此数组中 function isInArray(arr, str) { var testStr = ',' + arr.join(",") + ","; return testStr.indexOf("," + str + ",") != 1 ; } ......
//检测某个字符是否在此数组中
function isinarray(arr, str) {
    var teststr = ',' + arr.join(",") + ",";
    return teststr.indexof("," + str + ",") != -1 ;
}
var arr = ["101", "102", "103"];
console.log(isinarray(arr,"101"));//true

文章转自:https://blog.csdn.net/weixin_38052444/article/details/81805870