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

Code Example 1

colors = ['red', 'green', 'blue']
colors.each_with_index do |item, index|
	p "#{index}:#{item}" 
end

"0:red"
"1:green"
"2:blue"

Learn ReactJs, React Native from akashmittal.com