M
Mike
I have a list of numbers, e.g., (1,3,4,5,8,16,20), and am trying to
create a simple IF statement to see if the value is in that list. Is
there an easier or more efficient way, than the sample code below, to
do it?
=====
<script type="text/javascript">
num = 2;
list = [1,3,4,5,8,16,20];
if(isInList( num, list )) {
alert("It's there!");
} else {
alert("It's NOT there!");
}
function isInList( num, list ) {
// List is an Array()
result = false;
for(i in list) {
if(num == list) { result = true }
}
return result
}
</script>
create a simple IF statement to see if the value is in that list. Is
there an easier or more efficient way, than the sample code below, to
do it?
=====
<script type="text/javascript">
num = 2;
list = [1,3,4,5,8,16,20];
if(isInList( num, list )) {
alert("It's there!");
} else {
alert("It's NOT there!");
}
function isInList( num, list ) {
// List is an Array()
result = false;
for(i in list) {
if(num == list) { result = true }
}
return result
}
</script>