ruby on rails - Looping two different array at same time -



ruby on rails - Looping two different array at same time -

i have loop through 2 different arrays @ same time. let's have 2 arrays this:

a1 = ["a","b","c","d"] a2 = ["e","f","g","h"]

i want output this:

a,e b,f c,g d,h

i tried program, printing both arrays 2 times:

a1 = ["a","b","c","d"] a2 = ["e","f","g","h"] a1.each |a| a2.each |b| puts a[0] puts b[0] end end

loop through 1 array, , utilize current index element want in other array:

a1.each_with_index |a, i| puts "#{a},#{a2[i]}" end

ruby-on-rails ruby arrays loops hash

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -