将哈希数组转换为数组 [英] Convert array of hashes to array

查看:130
本文介绍了将哈希数组转换为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个哈希数组,从中我需要一个新数组中的哈希值.散列数组看起来像这样,有成千上万个.

I have an array of hashes from which I need the values of the hashes in a new array. The array of hashes look likes this, with a couple thousand of them.

array = [{:code=>"404"}, {:code=>"302"}, {:code=>"200"}]

我试图进行查找,但只发现了如何从哈希表进行转换.

I have tried to look this up but have only found out how to convert from a hash.

我该怎么做?

推荐答案

a=[{:code=>"404"}, {:code=>"302"}, {:code=>"200"}] 
puts a.map{|x|x.values}.flatten.inspect

输出

["404", "302", "200"]

这篇关于将哈希数组转换为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆