Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
55
rated 0 times [  56] [ 1]  / answers: 1 / hits: 22027  / 12 Years ago, tue, september 25, 2012, 12:00:00

I have two Javascript arrays of same size



var demo=new Array();
var demo3=new Array();


I need to access the value of the two array in one each loop in JQuery code.After surfing for a while I came across zip operation and I tried using the code



$.zip(demo,demo3).each(function(){                                   
alert(demo +this[0]);
alert(demo3 +this[1]);
});


However this code does not work.Please help.


More From » jquery

 Answers
41

Since they're the same size, just loop one, and reference the other with i.



$.each(demo, function(i, item) {
console.log(demo[i], demo3[i]);
});


If you don't need the indices paired, then just run them back to back by using .concat.



$.each(demo.concat(demo3), function(i, item) {
console.log(item);
});

[#82917] Sunday, September 23, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
josefinap

Total Points: 548
Total Questions: 125
Total Answers: 106

Location: Angola
Member since Tue, May 5, 2020
4 Years ago
;