How to access array Elements in Ruby Last Updated : 24 Oct, 2019 Comments Improve Suggest changes Like Article Like Report 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. Using Index - ruby # Ruby program to demonstrate the # accessing the elements of the array # creating string using [] str = ["GFG", "G4G", "Sudo", "Geeks"] # accessing array elements # using index puts str[1] # using the negative index puts str[-1] Output: G4G Geeks 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 # 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 For multi-dimensional array ruby # 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 Comment More infoAdvertise with us Next Article How to access array Elements in Ruby S Shivam_k Follow Improve Article Tags : Python Ruby Ruby Array Practice Tags : python Similar Reads Add array elements in Ruby In this article, we will learn how to add elements to an array in Ruby.Method #1: Using Index Ruby # Ruby program to add elements # in array # creating string using [] str = ["GFG", "G4G", "Sudo", "Geeks"] str[4] = "new_ele"; print str # in we skip t 1 min read How to Access elements of nested hashes in Ruby? RIn this article, we will discuss how to access elements of nested hashes in Ruby. We can access elements of nested hashes through different methods ranging from using the dig method to the fetch method. Table of Content Access elements of nested hashes using square bracketsAccess elements of nested 2 min read Remove array elements in Ruby In this article, we will learn how to remove elements from an array in Ruby. Method #1: Using Index Ruby # Ruby program to remove elements # in array # creating string using [] str = ["GFG", "G4G", "Sudo", "Geeks"] str.delete_at(0) print str Output: ["G4G", "S 1 min read How to convert Array to Hash in Ruby? In this article, we will discuss how to convert an array to a hash in Ruby. Converting an array to a hash can be useful when we have data in an array format and need to organize it into key-value pairs for easier access and manipulation. Table of Content Converting array to hash using Hash::[] const 3 min read Ruby | Array to_a() function Array#to_a() : to_a() is a Array class method which returns self array. Syntax: Array.to_a() Parameter: Array Return: self array representation Example #1 : Ruby # Ruby code for to_a() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c 1 min read How to Remove Duplicate Elements from Array in Ruby? This article focuses on discussing how to remove duplicate elements from an array in Ruby. In Ruby, an array is a fundamental data structure that stores a collection of elements in a specific order. Various methods and approaches can be used to remove duplicate elements from an array. Removing Dupli 2 min read How can we access the entries of a Hash in Ruby? In this article, we will discuss how to access the entries of a Hash in ruby. We can access the entries of a Hash through different methods ranging from using keys, and values to each method Table of Content Accessing the entries of a Hash using Hash.keys methodAccessing the entries of a Hash using 2 min read How to Make a Custom Array of Hashes in Ruby? Prerequisites: Hashes and Arrays in Ruby Arrays and hashes are data structures that allow you to store multiple values at once. In this article, we will explore their syntax, how to combine functionalities of both to create an array of hashes, retrieve values, and loop through them. An array is a co 3 min read How to check if a value exists in an Array in Ruby? In this article, we will discuss how to check if a value exists in an array in ruby. We can check if a value exists in an array through different methods ranging from using Array#member? method and Array#include? method to Array#any? method Table of Content Check if a value exists in an array using 3 min read Find maximum array element in Ruby In this article, we will learn how to find maximum array element in Ruby. There are multiple ways to find maximum array element in Ruby. Let's understand each of them with the help of example. Example #1: ruby # max function on list arr =[1, 2, 3, 4, 5].max print arr print "\n" str1 = [1, 1 min read Like