Check out example codes for "ruby loop each with index". It will help you in understanding the concepts better.

Code Example 1

X.each_with_index do |item, index|
  puts "current_index: #{index}"
end

Learn ReactJs, React Native from akashmittal.com