Home >Web Front-end >JS Tutorial >js uses for loop to query whether a certain value exists in an array_javascript skills
It should be because IE8 does not support indexOf, so write a for loop method to determine whether it exists and return true false
function isCon(arr, val){ for(var i=0; i<arr.length; i++){ if(arr[i] == val) return true; } return false; }
Add this method in js and call the method at the calling location
window.onload = function(){ var arr=new Array(1,2,3,2,4,2,5,6,7,2,4,3,18,12,41,87); alert(isCon(arr, 8)); }