Rearrange JavaScript array using match - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

Rearrange JavaScript array using match

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  ww w  .  ja v a 2s . c om
    var arr = ["A C", "B B", "C"];
    var newarr = [];
    var str = "C";
    for(var i = 0; i < arr.length; i++) {
      if(arr[i].toLowerCase().match(str.toLowerCase())){
         newarr[newarr.length] = arr[i];
      }
    }
    console.log(newarr);
    }

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

Related Tutorials