Use the array's built-in length method, which returns the number of elements in the array : Array Length « Array « Ruby






Use the array's built-in length method, which returns the number of elements in the array


array = ["Hello", "there", "AAA", 1, 2, 3]
puts array[1]       #prints "there"
puts array[4]       #prints 2
puts array.length   #prints 6

 

Related examples in the same category