How to print array values and the indexes in Ruby

1 Answer

0 votes
array = ["Ruby", "Open", "Source", "Programming", "Language"]

array.each_with_index {|val, index| puts "#{val} => #{index}" }


  
# run:
# 
# Ruby => 0
# Open => 1
# Source => 2
# Programming => 3
# Language => 4
#

 



answered Mar 22, 2025 by avibootz

Related questions

...