判断是否存在于数组中
<script>
function inArray(val, arr) {
for (var i = 0, len = arr.length; i < len; i++) {
if (arr[i] === val) return i;
}
return -1;
}
console.log(inArray(3, [1, 3, 8, 9, 6, 2, 4]))
</script>