簡體   English   中英

向數組添加哈希?

[英]Add a hash to an array?

我現在有這個哈希:

{:residential=>"false"}

但我需要將它作為數組的項目:

[{:residential=>"false"}]

我怎么做?

my_array = []
my_array << {:residential => "false"}
=> [{:residential=>"false"}]

您已編寫的代碼應該沒問題。

>> x = [{:residental=>"false"}, {:residental=>"true"}]                  
=> [{:residental=>"false"}, {:residental=>"true"}]                      
>> x[0][:residental]                                                    
=> "false"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM