Use for to loop through array index : in « Statement « Ruby






Use for to loop through array index


array = ['cherry', 'strawberry', 'orange']

for index in (0...array.length)
  puts "At position #{index}: #{array[index]}"
end

 








Related examples in the same category

1.For each element in an array
2.For each element in a range