At a certain point in my webapp I have the following (large) series of loops:
jQuery.each(GO, function(index, item){ $("#GO_PUBS").append(
"<li><a href=javascript:dopage('"+item+"');>"+GO_desc[index]+"</a></li>");});
jQuery.each(AP, function(index, item){ $("#AP_PUBS").append(
"<li><a href=javascript:dopage('"+item+"');>"+AP_desc[index]+"</a></li>");});
jQuery.each(BV, function(index, item){ $("#BV_PUBS").append(
"<li><a href=javascript:dopage('"+item+"');>"+BV_desc[index]+"</a></li>");});
jQuery.each(FI, function(index, item){ $("#FI_PUBS").append(
"<li><a href=javascript:dopage('"+item+"');>"+FI_desc[index]+"</a></li>");});
The loop goes on and on but the pattern is always the same.
Is there any way I can make it way shorter by using some sort of array or list instead of explicitly writing it loop?
Thanks
XXanXX_descarray too suggests that you should fix your internal data representation first. Perhaps (for example) you need a 2D structure, not a whole load of separate 1D structures?