title: Parsing json object from a variable to classes where key = class
body: <p>I am trying to parse a json object from a variable in an each() object.</p>
  
  <p>For example I have this long array:</p>
  
  <pre><code>{castle: "0", commercial: "3", common: "0", cultural: "2", dioni: "0", holidays: "0", island: "2", nereides: "2", others: "0", peninsula: "0", thetis: "0"}
  </code></pre>
  
  <p>and I have div's with the same classes as those keys of the array. For example:</p>
  
  <pre><code>&lt;div class="castle"&gt;&lt;/div&gt;
  &lt;div class="commercial"&gt;&lt;/div&gt;
  &lt;div class="common"&gt;&lt;/div&gt;
  &lt;div class="cultural"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>etc.</p>
  
  <p>So <strong>I want to append the value of each key to the class where class = key</strong>.</p>
  
  <pre><code>$("body div").each(function(){
     var array = [] // the reall long array;
  
     var a = $(this).attr("class").split(' ')[0]; // in case there are two divs, split
     $("." + a).text(array.a + " hours"); // array.a doesn't work
  
  });
  </code></pre>
  
  <p>In this case, array.a doesn't not exist in the array so I cannot parse the value of each key to each class.</p>
  
  <p>How can I solve this?</p>