<script type=text/javascript>
var dd=[1,3,4,6,8.2,"w",7,"d","q"]
var df=["a","d","f","g","h","w","q"]
for (i=0;i<10;i++){
if (dd[i] in df) {
document.write(dd[i]+ " " +i);
}
}
</script>
Try using the indexOf() method for arrays. This will let you run the same loop and simply check if the value exists in the array or not. The indexOf() function will return the location of the item in that array if it's found, otherwise it returns a -1.
Code:
<script type=text/javascript>
var dd = [1,3,4,6,8.2,"w",7,"d","q"];
var df = ["a","d","f","g","h","w","q"];
for(i = 0 ; i < 10 ; i++) {
if(df.indexOf(dd[i]) >= 0) {
document.write(dd[i] + " " + i + "<br>");
}
}
</script>
"Given billions of tries, could a spilled bottle of ink ever fall into the words of Shakespeare?"
Bookmarks