Iterating jquery each loop for two arrays at once

后端 未结 4 1468
感动是毒
感动是毒 2020-12-10 14:30

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 e

4条回答
  •  攒了一身酷
    2020-12-10 14:52

    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);
    });
    

提交回复
热议问题