Get array elements whose index is matching variable with array filter method - Javascript Array Operation

Javascript examples for Array Operation:Array Index

Description

Get array elements whose index is matching variable with array filter method

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(){//w w w  .  j a va 2s  .  co  m
var numbers = ["one", "two", "three", "four", "five", "six", "seven"];
var search = 'f';
console.log(numbers.filter(function(x){ if(x.indexOf(search) >= 0) return x }))
    }

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

Related Tutorials