When you group it status_json.group_by { |h| h["ncds"] }
you get a hash with three keys, because it's what group_by
does:
{
[nil, nil, "2020-05-31"]=>[
{"enquiries_ids"=>[65219, 65210, 65194], "ncds"=>[nil, nil, "2020-05-31"], "broker_id"=>256, "status_id"=>49, "visit_date"=>nil}
],
[nil, nil]=>[
{"enquiries_ids"=>[65220, 65221], "ncds"=>[nil, nil], "broker_id"=>351, "status_id"=>49, "visit_date"=>nil},
{"enquiries_ids"=>[65218, 65217], "ncds"=>[nil, nil], "broker_id"=>599, "status_id"=>49, "visit_date"=>nil}
],
[nil]=>[
{"enquiries_ids"=>[65227], "ncds"=>[nil], "broker_id"=>403, "status_id"=>49, "visit_date"=>#<Date: 2020-05-20>},
{"enquiries_ids"=>[65228], "ncds"=>[nil], "broker_id"=>449, "status_id"=>49, "visit_date"=>nil}
]
}
To collect all arrays in a new one you can iterate through status_json
using flat_map
:
bk = status_json.flat_map { |h| h["ncds"] }
Which gives you:
[nil, nil, "2020-05-31", nil, nil, nil, nil, nil, nil]