I cannot think of a way to loop through two arrays at the same time. This code is for outputting a function's data to different divs on a page. array1
defines the input and array2
defines the output.
How can I loop through the two arrays so that item1
will always be paired with '#div1'
, item2
with '#div2'
, etc.
var array1=[item1 , item2, item3, item4];
var array2=['#div1', '#div2', '#div3', '#div4'];
for (var i = 0; i < array1.length; i++) {
//code for to populate data goes here
item.appendTo($(array2[i]));
};
Am I at least correct in wrapping my function in a for loop?
Thank you!