Ruby | Array class find_index() operation Last Updated : 08 Jan, 2020 Comments Improve Suggest changes Like Article Like Report Array#find_index() : find_index() is a Array class method which returns the index of the first array. If a block is given instead of an argument, returns the index of the first object for which the block returns true. Syntax: Array.find_index() Parameter: block - condition to follow Return: index value of the array elements Code #1 : Example for find_index() method Ruby # Ruby code for find_index() method # declaring array a = [18, 22, 33, nil, 5, 6] # declaring array b = [1, 4, 1, 1, 88, 9] # declaring array c = [18, 22, nil, nil, 50, 6] # find_index puts "find_index : #{a.find_index(5)}\n\n" # find_index puts "find_index : #{b.find_index(4)}\n\n" # find_index puts "find_index : #{c.find_index(nil)}\n\n" Output : find_index : 4 find_index : 1 find_index : 2 Code #2 : Example for find_index() method Ruby # Ruby code for find_index() method # declaring array a = ["abc", "nil", "dog"] # declaring array b = ["cow", nil, "dog"] # declaring array c = ["cat", nil, nil] # find_index puts "find_index : #{a.find_index("abc")}\n\n" # find_index puts "find_index : #{b.find_index(nil)}\n\n" # find_index puts "find_index : #{c.find_index(nil)}\n\n" Output : find_index : 0 find_index : 1 find_index : 1 Comment More infoAdvertise with us Next Article Ruby | Array class find_index() operation M mayank5326 Follow Improve Article Tags : Ruby Ruby Collections Ruby Array-class Similar Reads Ruby | Array class each_index() operation Array#each_index() : each_index() is a Array class method which returns the index of the array element by following the condition in the given block once for each_index element in self. Syntax: Array.each_index() Parameter: block - condition to follow Return: index of the array element following the 1 min read Ruby | Array class include?() operation Array#include?() : include?() is a Array class method checks if the argumented object is present in the array or not. Syntax: Array.include?() Parameter: obj - element to find Return: true - if the element is present; otherwise false Code #1 : Example for include?() method Ruby # Ruby code for inclu 1 min read Ruby | Array class fill() operation Array#fill() : fill() is a Array class method which fills the array with the element and that can be in a specific range. Syntax: Array.fill() Parameter: Array, element, range Return: array with specific element in the given range. Code #1 : Example for fill() method Ruby # Ruby code for fill() meth 2 min read Ruby | Array class fetch() operation Array#fetch() : fetch() is a Array class method which returns the element at the argument index position. Syntax: Array.fetch() Parameter: index value Return: element at the argument index value Code #1 : Example for fetch() method Ruby # Ruby code for fetch() method # declaring array a = [18, 22, 3 1 min read Ruby | Array class eql?() operation Array#eql?() : eql?() is a Array class method which checks if the two arrays are equal or not. Syntax: Array.eql?() Parameter: Arrays to compare Return: true - if the arrays are equal; otherwise false Code #1 : Example for eql?() method Ruby # Ruby code for eql?() method # declaring array a = [18, 2 1 min read Ruby | Array class frozen?() operation Array#frozen?() : frozen?() is a Array class method which checks whether the array is frozen (or temporarily frozen while being sorted) Syntax: Array.frozen?() Parameter: Array to check Return: true - if array is frozen; otherwise false Code #1 : Example for frozen?() method Ruby # Ruby code for fro 1 min read Ruby | Array class each() operation Array#each() : each() is a Array class method which returns the array by following the condition in the given block once for each element in self. Syntax: Array.each() Parameter: block - condition to follow Return: Each array element following the condition Code #1 : Example for each() method Ruby # 1 min read Ruby | Array class empty?() operation Array#empty?() : empty?() is a Array class method which checks if the array is empty or not. Syntax: Array.empty?() Parameter: Array Return: true - if no element is present in the array; otherwise false Code #1 : Example for empty?() method Ruby # Ruby code for empty?() method # declaring array a = 1 min read Ruby | Array bsearch_index() operation Array#bsearch_index() : bsearch_index() is an Array class method which finds the index of the array value that meets with the given condition. Its complexity is O(log n) where n is the array size. This method can work in both the modes - find-minimum and find-any mode. Syntax: Array.bsearch_index() 2 min read Ruby | Array class index() function index() is an Array class method which returns the index of the first object in the array. Syntax: Array.index() Parameter: Array obj - object to search for Return: Index value of the first array Example #1 : Ruby # Ruby code for index() method # declaring array a = [18, 22, 33, nil, 5, 6] # declari 1 min read Like