title: How can I filter data in json file?
body: <p>I've a external JSON file like this:</p>
  <pre><code>{&quot;colors&quot;:[{
          &quot;color&quot;: &quot;red&quot;,
          &quot;value&quot;: &quot;#f00&quot;
      },
      {
          &quot;color&quot;: &quot;green&quot;,
          &quot;value&quot;: &quot;#0f0&quot;
      },
      {
          &quot;color&quot;: &quot;blue&quot;,
          &quot;value&quot;: &quot;#00f&quot;
      }]}
  </code></pre>
  <p>I want to filter data in order to obtain the name giving the value. This is my code:</p>
  <pre><code>$.ajax({
          url: &quot;./data.json&quot;,
          dataType: &quot;json&quot;,
          type: &quot;get&quot;,
          cache: false,
          success: function (json){
              $(json.colors).each(function(i,data){
  
                  let key=&quot;value&quot;;
                  let value=&quot;#00f&quot;;
                  let result= data.filter(d=&gt;d[key]==value);
                  console.log(result)
  
              
              });
          }
      })
  </code></pre>
  <p>Obv it doesn't work. How can I resolve this? Thanks in advance to who will help me.</p>
  <p><div class="snippet" data-lang="js" data-hide="true" data-console="true" data-babel="false">
  <div class="snippet-code snippet-currently-hidden">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const json = `{"colors":[{
    "color": "red",
    "value": "#f00"
  },
  {
    "color": "green",
    "value": "#0f0"
  },
  {
    "color": "blue",
    "value": "#00f"
  }]}`;
  
  function fakeAjax(options) {
      setTimeout(() =&gt; {
          options.success(JSON.parse(json));
      }, 800);
  }
  
  fakeAjax({
      url: "./data.json",
      dataType: "json",
      type: "get",
      cache: false,
      success: function (json){
          $(json.colors).each(function(i,data){
              let key="value";
              let value="#00f";
              let result= data.filter(d=&gt;d[key]==value);
              console.log(result)
  
  
          });
      }
  })</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>