title: Basic javascript / JSON grabbing elements from list
body: <p>I have a PHP array of data $mainarray that I'm trying to manipulate with javascript. </p>
  
  <p>I did this: </p>
  
  <pre><code>var masterdata = &lt;?php echo json_encode($mainarray); ?&gt;;
  </code></pre>
  
  <p>To check how that came through, I did this: </p>
  
  <pre><code>alert(JSON.stringify(masterdata, null, 4));
  </code></pre>
  
  <p>And I got this: </p>
  
  <pre><code>{
  "Department":"Fire",
  "Year":"2014",
  "Amount":"311.3"
  },
  {
  "Department":"Police",
  "Year":"2014",
  "Amount":"622.3"
  },
  {
  "Department":"Vehicles",
  "Year":"2014",
  "Amount":"100.9"
  }
  ...
  </code></pre>
  
  <p>I now just want to loop through every one of those bracketed sets and do something like </p>
  
  <pre><code>if (masterdata[Department] == "Fire" &amp;&amp; masterdata[Year] == "2014") 
      fireamount2014 = masterdata[Amount];
  </code></pre>
  
  <p>but I think that syntax is nowhere close and I am going mad from lack of basic understanding of how this works. </p>