<script type="text/javascript">
//alert(in_array(5,[1,2,3,4,5],true));
var needle = 'c';
var array = ['a','b','c','d','e'];
alert(in_array(needle,array,true));
function in_array(needle, array, bool) {
if (typeof needle == "string" || typeof needle == "number") {
for (var i in array) {
if (needle === array[i]) {
if (bool) {//如果有第三个参数,就返回在数组中的位置
return i;
}
return true;
}
}
return false;
}
}
</script>