title: Javascript multiple condition array filter
body: <p>I need help putting together an array search that is based on multiple conditions.  Furthermore, all the conditions are conditional, meaning I may or may not need to filter on those conditions.  What I have:</p>
  
  <p>Array of objects to filter:</p>
  
  <pre><code>var data = [{
      "_id" : ObjectId("583f6e6d14c8042dd7c979e6"),
      "transid" : 1,
      "acct" : "acct1",
      "transdate" : ISODate("2012-01-31T05:00:00.000Z"),
      "category" : "category1",
      "amount" : 103
  },
  {
      "_id" : ObjectId("583f6e6d14c8042dd7c2132t6"),
      "transid" : 2,
      "acct" : "acct2",
      "transdate" : ISODate("2012-01-31T05:00:00.000Z"),
      "category" : "category2",
      "amount" : 103
  },
  {
      "_id" : ObjectId("583f6e6d14c8042dd7c2132t6"),
      "transid" : 3,
      "acct" : "acct2",
      "transdate" : ISODate("2016-07-31T05:00:00.000Z"),
      "category" : "category1",
      "amount" : 103
  },
  {
      "_id" : ObjectId("583f6e6d14c8042dd7c2132t6"),
      "transid" : 4,
      "acct" : "acct2",
      "transdate" : ISODate("2012-01-31T05:00:00.000Z"),
      "category" : "category2",
      "amount" : 103
  },
  {
      "_id" : ObjectId("583f6e6d14c8042dd7c2132t6"),
      "transid" : 5,
      "acct" : "acct2",
      "transdate" : ISODate("2012-01-31T05:00:00.000Z"),
      "category" : "category3",
      "amount" : 103
  },
  {
      "_id" : ObjectId("583f6e6d14c8042dd7c152g2"),
      "transid" : 6,
      "acct" : "acct3",
      "transdate" : ISODate("2016-10-31T05:00:00.000Z"),
      "category" : "category3",
      "amount" : 103
  }]
  </code></pre>
  
  <p>I am filtering the above array of objects based on another array of mixed elements.  The elements represent the following search fields: </p>
  
  <ul>
  <li><p>"searchstring": to search on all fields in the data array for any
  matched text sequence </p></li>
  <li><p>object with key values reprsenting account type and a  true or false
  for value indicating if it should be used to filter </p></li>
  <li><p>startdate to filter transdate on</p></li>
  <li><p>enddate to filter transdate</p></li>
  <li><p>category name to filter category on</p></li>
  </ul>
  
  <p>The array that has the search conditions looks like this (but if some of the fields are not necessary they will be set to undefined or just an empty string or array):</p>
  
  <pre><code>var filtercondition = {
      "p",
      {acct1:true,acct2:false,acct3:true...}
      "2016-06-01",
      "2016-11-30",
      "category3"
  }
  </code></pre>
  
  <p>What is the best way to accomplish this?  What I've devised is a separate search for each element in the filter array, but this seems non optimal and very tedious.  I'm open to a redesign of my setup...</p>