Remove several words from an array by regex - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

Remove several words from an array by 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() {/* www . ja v a 2  s  .c  o  m*/
var words = ['the', 'it', '12', '#twit', '#aloha', 'hello#', 'bye']
var filteredWords = []
for (var i = 0, l = words.length, w; i < l; i++) {
    w = words[i]
    if (!/^(#|\d+)/.test(w) && w.length > 3)
        filteredWords.push(w)
}
console.log(filteredWords)
    });

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

Related Tutorials