<script>
function in_array(stringToSearch, arrayToSearch) {
for (s = 0; s < arrayToSearch.length; s++) {
thisEntry = arrayToSearch[s].toString();
if (thisEntry == stringToSearch) {
return true;
}
}
return false;
}
var arr = [1,2,3,4,5];
if(in_array(3,arr)){
alert(1);
}else{
alert(2);
}
</script>
JS 判断某个字符串是否存在与数组中
最新推荐文章于 2022-12-01 09:15:51 发布