Alex Rivera | Logout

Iterating jquery each loop for two arrays at once

Asked 2012-09-25T14:39:57.387
10

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.

Edit
Report

1 Answer

10

Sure they'll keep same size? Use a good ol' for:

for(var i = 0; i < demo.length; i++){
    console.log(demo[i]);
    console.log(demo3[i]);
}
answered 2012-09-25T14:41:36.773

Your Answer