What is the “right” way to iterate through an array in Ruby?
This will iterate through all the elements: array = [1, 2, 3, 4, 5, 6] array.each { |x| puts x } # Output: 1 2 3 4 5 6 This will iterate through all the elements giving you the value and the index: array = [“A”, “B”, “C”] array.each_with_index {|val, index| puts “#{val} => #{index}” … Read more