Total members 11893 |It is currently Tue Nov 05, 2024 1:30 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





check array contains a value using JavaScript
Code:

<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>




_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 1 post ] 

  Related Posts  to : check array contains a value using javascript
 Array difference for associate array     -  
 Check DNS error     -  
 check if domain name is taken by php     -  
 check if number is odd or even     -  
 compare an array with another array?     -  
 Check empty string     -  
 check empty number     -  
 check request was GET or POST     -  
 code for check availability     -  
 check keyboard events using C++     -  



Topic Tags

JavaScript Arrays
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
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