# Finding Array Key / Value Pairs

**URL:** <https://www.ruby-forum.com/t/finding-array-key-value-pairs/71089>\
**Category:** Rails\
**Created:** [October 5, 2006, 8:22am UTC](https://www.ruby-forum.com/t/finding-array-key-value-pairs/71089 "2006-10-05T08:22:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![daborg69](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d9b06d/32.png) [@daborg69](https://www.ruby-forum.com/u/daborg69)\
**Post date:** [October 5, 2006, 8:22am UTC](https://www.ruby-forum.com/t/finding-array-key-value-pairs/71089/1 "2006-10-05T08:22:17Z")

</div>

Hello,

I have an order form on my site where people can enter in the number of  
products they want to buy. Once they have filled out the quantities and  
press continue the form values look like this:

Parameters: {“commit”=\>“Continue”, “order\_form”=\>{“127”=\>“3”,  
“128”=\>“1”, “129”=\>“0”, “130”=\>“0”, “136”=\>“0”, “137”=\>“0”, “126”=\>“2”}}

The first number in the “number pairs” is the ID of the product and the  
second is the quantity they entered.

How can I loop over the “order\_form” array a get both the first and  
second value?

Any help appreciated!

---

<div class="post-metadata">

**Author:** ![daborg69](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d9b06d/32.png) [@daborg69](https://www.ruby-forum.com/u/daborg69)\
**Post date:** [October 5, 2006, 8:46am UTC](https://www.ruby-forum.com/t/finding-array-key-value-pairs/71089/2 "2006-10-05T08:46:03Z")

</div>

On 10/4/06, Scott H. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> The first number in the “number pairs” is the ID of the product and the  
> second is the quantity they entered.
> 
> How can I loop over the “order\_form” array a get both the first and  
> second value?

params[:order\_form].each do |key,value|  
end

---

<div class="post-metadata">

**Author:** ![daborg69](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/d9b06d/32.png) [@daborg69](https://www.ruby-forum.com/u/daborg69)\
**Post date:** [October 5, 2006, 8:50am UTC](https://www.ruby-forum.com/t/finding-array-key-value-pairs/71089/3 "2006-10-05T08:50:20Z")

</div>

Thanks, that is exactly what I was looking for. I just couldn’t find the  
answer anywhere.
