Find index in an array : find_index « Array « Ruby






Find index in an array


data = [[1,2], [0,1], [7,8]]
data.find_index {|x| x.include? 1} # => 0: the first element matches
data.find_index {|x| x.include? 3} # => nil: no such element

 

Related examples in the same category