Count instances of string in an array using regex - Javascript RegExp

Javascript examples for RegExp:RegExp Match

Description

Count instances of string in an array using regex

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(){/*from  w  w w  .j a  v a2s . c om*/
var numOfTrue = 0;
var Answers = [ "true", "false", "false", "true", "false" ];
console.log(Answers.toString().match(/true/g).length);
    }

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

Related Tutorials