each_with_index to iterate of items using index
We have already used
each method of Ruby Array.
Ruby Array also has a method called
If we use
each_with_index then besides getting the value we also
get the index (position) of the value in the array.
When we use
each_with_index then we also get the position of the each value.
Note that first position is zero. Our users might not like the first position as zero. This is how we can fix it.