Hello all, newbie here.
The title is quite self explanatory: I am in
dummy_array.each do |a|
#code here
end
and I want to know which element (the number n in nth element) of the
dummy_array.
Thanks in advance
Hello all, newbie here.
The title is quite self explanatory: I am in
dummy_array.each do |a|
#code here
end
and I want to know which element (the number n in nth element) of the
dummy_array.
Thanks in advance
The title is quite self explanatory: I am in
dummy_array.each do |a|
#code here
endand I want to know which element (the number n in nth element) of the
dummy_array.
You could just put a counting variable in there:
i = 0
dummy_array.each do |a|
i = i+1
#code here
end
You can also use each_index on the array if you’d like.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs