zaagan
12/29/2019 - 8:22 AM

Ruby Basics - Each with Index

Ruby Basics - Each with Index

prices = [2, 3, 4]

prices.each_with_index do |item, index|
  p "At #{index} we have #{item}"
end

# Output >
# "At 0 we have 2"
# "At 1 we have 3"
# "At 2 we have 4"