For multi-dimensional array
# Ruby program to demonstrate the # accessing the multiple elements # from array # creating string using [] str = [[ "GFG" , "G4G" , "Sudo" ], [ "Geeks" , "for" , "portal" ] ] # accessing item from multi-array puts str[ 1 ][ 2 ] |
Output:
portal
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