# How to find position in an array

**URL:** <https://www.ruby-forum.com/t/how-to-find-position-in-an-array/125591>\
**Category:** Rails\
**Created:** [January 10, 2008, 12:28pm UTC](https://www.ruby-forum.com/t/how-to-find-position-in-an-array/125591 "2008-01-10T12:28:54Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [January 10, 2008, 12:28pm UTC](https://www.ruby-forum.com/t/how-to-find-position-in-an-array/125591/1 "2008-01-10T12:28:54Z")

</div>

I have an array:

r1.rp\_parts:  
[\<Rp1…\>][\<Rp1…\>][\<Rp1…\>][\<Rp4…\>]

If I do:  
r1.rp\_parts[2]  
I obtain  
Rp1…

I would like to obtain de position of r1.rp\_parts[2] in the r1.rp\_parts  
array. I know that it’s position is 2, but I wonder if I can obtain the  
position from r1.rp\_parts[2].

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [January 10, 2008, 3:27pm UTC](https://www.ruby-forum.com/t/how-to-find-position-in-an-array/125591/2 "2008-01-10T15:27:05Z")

</div>

John S. wrote:

> I have an array:
> 
> r1.rp\_parts:  
> [\<Rp1…\>][\<Rp1…\>][\<Rp1…\>][\<Rp4…\>]
> 
> If I do:  
> r1.rp\_parts[2]  
> I obtain  
> Rp1…
> 
> I would like to obtain de position of r1.rp\_parts[2] in the r1.rp\_parts  
> array. I know that it’s position is 2, but I wonder if I can obtain the  
> position from r1.rp\_parts[2].

Use the index method of Array:

some\_part = r1.rp\_parts[2]  
r1.rp\_parts.index(some\_part) #=\> 2
