Home › Forums › JavaScript › help optimizing code › Re: help optimizing code
November 14, 2009 at 1:15 pm
#66552
Member
I’ve made it a little bit more dynamic even…
Code:
jQuery.each(allSoldierTypes, function(k, v) {
//console.log(v);
jQuery.each(v, function(keys, vals) {
//console.log(v);
jQuery.each(v, function(keys, vals) {
$(‘
“‘).appendTo(“.” + k).text(“keys: ” + keys + ” Vals: ” + vals);
});
});
This uses jQuery to do the looping via jQuery.each(); I created a new object literal called allSoldierTypes, which uses the name of the solider object as its name, and the object itself as it’s value, for example, demolitions: demolitions
First I loop through each soldier type, as that is looping i use it’s key to populate another loop with the current soldier type’s name. this loop goes through each attribute of the soldier, and creates paragraphs and appends them inside the proper div…
not sure how much more dynamic i could get…