Use $.map instead of for loops where possible