javascript - Looping array inside and array -


i'm want loop array inside , array using javascript

outerarray = ["1","2","3","4","5","6","7","8","9","10"]; innerarray = ["val-1","val-2","val-3"]; 

so console logs out:

1,val-1 2,val-2 3,val-3 4,val-1 5,val-2 6,val-3 7,val-1 8,val-2 9,val-3 10,val-1 

using:

for (var = 0; < outerarray.length; i++) {     console.log(i); } 

obviously logs: 1,2,3,4,5,.....

however cant use:

for (var = 0; < outerarray.length; i++) {     console.log(i+','+innerarray[i]); } 

as give undefined after "val-3" different length outer array.

you seem want

console.log(outerarray[i]+','+innerarray[i%innerarray.length]); 

reference on % operator


Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -