# Remove array within hash

**URL:** <https://www.ruby-forum.com/t/remove-array-within-hash/194321>\
**Category:** Rails\
**Created:** [September 2, 2010, 12:49pm UTC](https://www.ruby-forum.com/t/remove-array-within-hash/194321 "2010-09-02T12:49:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmanivannancse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@jmanivannancse](https://www.ruby-forum.com/u/jmanivannancse)\
**Post date:** [September 2, 2010, 12:49pm UTC](https://www.ruby-forum.com/t/remove-array-within-hash/194321/1 "2010-09-02T12:49:33Z")

</div>

My orginal hash is like as

==\> hash = {“sku\_id”=\>[4], “brand\_active”=\>[“true”],  
“salesman\_active”=\>[“true”]}

How to remove the array within hash. that means to convert the hash like

==\> {“sku\_id”=\>4, “brand\_active”=\>“true”, “salesman\_active”=\>“true”

---

<div class="post-metadata">

**Author:** ![jmanivannancse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@jmanivannancse](https://www.ruby-forum.com/u/jmanivannancse)\
**Post date:** [September 2, 2010, 12:59pm UTC](https://www.ruby-forum.com/t/remove-array-within-hash/194321/2 "2010-09-02T12:59:31Z")

</div>

Come on, why even ask this!? Check the doc for all essentials – Array,  
Hash, String.

hash.each { |k,v| hash[k] = v[0] }

- A

---

<div class="post-metadata">

**Author:** ![jmanivannancse](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/8491ac/32.png) [@jmanivannancse](https://www.ruby-forum.com/u/jmanivannancse)\
**Post date:** [September 7, 2010, 7:31pm UTC](https://www.ruby-forum.com/t/remove-array-within-hash/194321/3 "2010-09-07T19:31:44Z")

</div>

On Sep 2, 6:49 am, Manivannan J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ==\> hash = {“sku\_id”=\>[4], “brand\_active”=\>[“true”],  
> “salesman\_active”=\>[“true”]}
> 
> How to remove the array within hash.

In addition to Aleksey’s response re how to UNdo the arraying, would  
it be possible simply to NOT put the data in as arrays in the first  
place?

-Dave
