title: Wildcard Filter Array of Objects - Javascript
body: <p>How do I implement a wildcard filter on an array of objects? Even if filter works only on from the start, that should be fine. Should be able to filter on all properties of the object. </p>
  
  <p>Should work in the same way as lodash filter works except for the fact that wildcard filter also works. Thanks.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const sampleProducts = [{
      color: 'red',
      value: '#f00',
    },
    {
      color: 'green',
      value: '#0f0',
    },
    {
      color: 'blue',
      value: '#00f',
    },
    {
      color: 'cyan',
      value: '#0ff',
    },
    {
      color: 'magenta',
      value: '#f0f',
    },
    {
      color: 'yellow',
      value: '#ff0',
    },
    {
      color: 'black',
      value: '#000',
    },
  ];
  
  const filteredResultsObj = {
    color: "red"
  }
  
  const filteredData = _.filter(sampleProducts, filteredResultsObj)
  
  console.log(filteredData)</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.11/lodash.min.js"&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>I can only do a whole word filter. Any advice on to implement a wild card filter such like this?</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const sampleProducts = [{
      color: 'red',
      value: '#f00',
    },
    {
      color: 'green',
      value: '#0f0',
    },
    {
      color: 'blue',
      value: '#00f',
    },
    {
      color: 'cyan',
      value: '#0ff',
    },
    {
      color: 'magenta',
      value: '#f0f',
    },
    {
      color: 'yellow',
      value: '#ff0',
    },
    {
      color: 'black',
      value: '#000',
    },
  ];
  
  const filteredResultsObj = {color: "bl", value: '#f0'}
  
    const filteredData = _.filter(sampleProducts, filteredResultsObj)
      
  // [{color: 'blue', value: '#00f'}, {color: 'black', value: '#000'}, {
      color: 'red',
      value: '#f00',
    }, {
      color: 'magenta',
      value: '#f0f',
    }]</code></pre>
  </div>
  </div>
  </p>
  
  <p>Only from the start, the data should be filtered as in the above example. Shouldn't filter values with bl in the middle. Thanks.</p>