Skip to content

Latest commit

 

History

History
16 lines (7 loc) · 310 Bytes

How_to_find_index_of_element_in_array_ruby.md

File metadata and controls

16 lines (7 loc) · 310 Bytes

How to find index of element in array ruby

We have an array of 9 numbers

a = [9,8,7,6,5,4,3,2,1]

We put the index value at the variable position, for which we use the a.index method.The index of this value is what we want to get.

position1 = a.index(8)

We show the result

puts position1