Ruby | Array rindex() function
Array#rindex() : rindex() is a Array class method which returns the index of the last object in the array.
Syntax: Array.rindex()
Parameter: Array
Return: the index of the last object in the array.
if not present then nil
Example #1 :
# Ruby code for rindex() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c = [18, 22, 50, 6] # rindex method example puts "rindex() method form : #{a.rindex(22)}\n\n" puts "rindex() method form : #{b.rindex(1)}\n\n" puts "rindex() method form : #{c.rindex(18)}\n\n" |
chevron_right
filter_none
Output :
rindex() method form : 1 rindex() method form : 3 rindex() method form : 0
Example #2 :
# Ruby code for rindex() method # declaring array a = ["abc", "nil", "dog"] # declaring array c = ["cat", nil] # declaring array b = ["cow", nil, "dog"] # rindex method example puts "rindex() method form : #{a.rindex("abc")}\n\n" puts "rindex() method form : #{b.rindex("cat")}\n\n" puts "rindex() method form : #{c.rindex("cat")}\n\n" |
chevron_right
filter_none
Output :
rindex() method form : 0 rindex() method form : rindex() method form : 0
Recommended Posts:
- Ruby | Array <=> function
- Ruby | Array &() function
- Ruby | Array pop() function
- Ruby | Array map() function
- Ruby | Array max() function
- Ruby | Array min() function
- Ruby | Array none?() function
- Ruby | Array take() function
- Ruby | Array zip() function
- Ruby Array () function with example
- Ruby | Array one?() function
- Ruby | Array shift() function
- Ruby | Array shuffle() function
- Ruby | Array assoc() function
- Ruby | Array length() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


