title: how to filter an array with index of condition in javascript
body: <p>Having less background of any coding, am trying to acheive a filtered array from an existing array with indexof condition in javascript.</p>
  
  <p>My code:</p>
  
  <pre><code>function CheckIfexists(element) {
    return (element.indexOf(formInput) &gt; -1);
  }
  var filtered = data.filter(CheckIfexists);
  window.alert(filtered[1] + " " + filtered[2] + " " + filtered[3]);
  </code></pre>
  
  <p>above code is not working</p>
  
  <p>addl info:</p>
  
  <p>forminput is input taken from form feild.</p>
  
  <pre><code>var formInput = document.getElementById("textReader").value;
  </code></pre>
  
  <p>data array i got by...</p>
  
  <pre><code>var data = oRequest.responseText.split("\r\n");
  </code></pre>
  
  <hr>
  
  <p>another way i tried is..</p>
  
  <pre><code>function CheckIfexists(formInput) {
     for (var i = 0; i &lt; data.length; i += 1) {
         if (data[i].indexOf(formInput) &gt; -1) {
             return false;
         }
     } 
     return true;
  }
  
  var filtered = data.filter(CheckIfexists);
  window.alert(filtered[1] + " " + filtered[2] + " " + filtered[3]);
  </code></pre>
  
  <p>the above code is also not working..</p>
  
  <hr>
  
  <p>donot doubt about data array and forminput beacuse i checked each element with code, al</p>
  
  <pre><code>for(var i=0; i&lt;data.length; i++) {  
      if (data[i] === formInput) {
          alert("You want to retrieve report?");
          didntfind = false;
          break;
      } 
  }
  
       if (didntfind) alert("sorry. part not found");
  </code></pre>
  
  <p>and i got the ones matching and not matching. 
  Addl note: data array has part names, forminput may not be exactly same as element in data array, it can also be partial..
  My struggle is to get the filtered ones in new array.</p>