I am trying to parse a json object from a variable in an each() object.
For example I have this long array:
{castle: "0", commercial: "3", common: "0", cultural: "2", dioni: "0", holidays: "0", island: "2", nereides: "2", others: "0", peninsula: "0", thetis: "0"}
and I have div's with the same classes as those keys of the array. For example:
<div class="castle"></div>
<div class="commercial"></div>
<div class="common"></div>
<div class="cultural"></div>
etc.
So I want to append the value of each key to the class where class = key.
$("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
});
In this case, array.a doesn't not exist in the array so I cannot parse the value of each key to each class.
How can I solve this?