replace for with jQuery.each for iterating over objects