title: Javascript Push to Array if Condition is Met
body: <p>I have the following Foods Object:</p>
  
  <pre><code>var Foods = {
    "Fruits": [{
     "id": "1",
     "Name": "Granny Smith",
     "Category": "1"
    }, {
     "id": "2",
     "Name": "Raspberries",
     "Category": "1"
     }
  ],
   "Potatoes": [{
     "id": "3",
     "Name": "Maris Piper",
     "Category": "2"
    }, {
     "id": "4",
     "Name": "Charlotte",
     "Category": "2"
   }]
   }
  </code></pre>
  
  <p>What I would like to do is only push the produce that matches an id passed by a link.</p>
  
  <pre><code>&lt;a href="javascript:void(0)" class="cat" id="2" onClick="getCat(this.id)"&gt;Get Foods&lt;/a&gt;
  </code></pre>
  
  <p>This is what I have tried so far:</p>
  
  <pre><code>function getCat (id){
   result = [];
   for(let item in Foods) {
      if(Foods[item].id == id) {
          data[item].foreach(v=&gt;result.push("&lt;div class='box'&gt;&lt;h2&gt;" + 
          data[key].Name + "&lt;br&gt;&lt;/div&gt;"));
      }
    }
  }
  
  display();
  
  function display() {
    alert(result);
  }
  </code></pre>
  
  <p>So if a user hits the link (which has an id of 2), the result array should contain "Charlotte" and "Maris Piper" but I am just drawing a blank.</p>
  
  <p>Any help appreciated.</p>
  
  <p>Cheers</p>