Accessing Elements : Array Elements « Array « Ruby

Accessing Elements

q1 = %w[ January February March ]

#you can access the first element of the array, element 0, with the 0 index:

q1[0] # => January

# Access the last element of the array, element 2, with:

q1[2] # => March


Related examples in the same category

1.have an array that contains objects from different classes, not all just one type.
2.use the at method
3.Access the last element in the array
4.With -1, you access the last element in an array by looping back around with a negative number.
5.To change three of the elements to have German rather than English spelling.
6.With start and length parameters
7.Replacing subarrays with []=
8.Change character case of an element