Search if a value is in an array - Javascript Array Operation

Javascript examples for Array Operation:Array Search

Description

Search if a value is in an array

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=( function() {//  www  . j a  va 2 s  . c  om
a = 1;
b = [1,2,3,4];
function check(a,b){
    for (var i=0;i<b.length;i++) {
        if (a == b[i]) {
             return true;
        }
    }
    return false;
}
console.log(check (a,b))

    });

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials