Check string with an array - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

Check string with an array

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <script>
var text = ["Joe", "a", "v", "Joe", "Joe", "xx"];
var myName = "Joe";
var hits = [];/*from   w  w  w. j a v a 2  s  .c om*/
for(var i = 0; i < text.length; i++) {
    if (text[i] === myName) {
            hits.push(text[i]);
    }
}
console.log(hits);

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

Related Tutorials