The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript help optimizing code Re: help optimizing code


I’ve made it a little bit more dynamic even…

jQuery.each(allSoldierTypes, function(k, 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…