Retrieving Multiple Elements from Array
Sometimes, we need to access the multiple elements from the array. So to access the multiple elements, pass the two specified array index into the [].
# Ruby program to demonstrate the # accessing the multiple elements # from array # creating string using [] str = [ "GFG" , "G4G" , "Sudo" , "Geeks" ] # accessing multiple array elements puts str[ 2 , 3 ] |
Output:
Sudo Geeks
How to access array Elements in Ruby
In this article, we will learn how to access array elements in Ruby.
In Ruby, there are several ways to retrieve the elements from the array. Ruby arrays provide a lot of different methods to access the array element. But the most used way is to use the index of an array.
Contact Us