Sun Sep 18, 2011 1:12 am
<html>
<title>check array contains</title>
<head>
<script language="JavaScript">
function checkContains(mycolor)
{
var colorArr= Array("RED", "BLUE", "YELLOW");
if(contains(colorArr,mycolor)) {
document.write(mycolor+'<b> Color</b> is there.');
}else{
document.write('Not there.');
}
}
// contains function
function contains(arr, findValue) {
var i = arr.length;
while (i--) {
if (arr[i] === findValue) return true;
}
return false;
}
</script>
</head>
<body>
<SCRIPT language="JavaScript">
checkContains("RED");
</SCRIPT>
</body>
</HTML>
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.