我有一个数组
array_hash = [
{
"array_value" => 1,
"other_values" => "whatever",
"inner_value" => [
{"iwantthis" => "forFirst"},
{"iwantthis2" => "forFirst2"},
{"iwantthis3" => "forFirst3"}
]
},
{
"array_value" => 2,
"other_values" => "whatever2",
"inner_value" => [
{"iwantthis" => "forSecond"},
{"iwantthis2" => "forSecond2"},
{"iwantthis3" => "forSecond3"}
]
},
]
我想删除内部值或将其弹出(我更喜欢弹出)。所以我的输出应该是这样的:
array_hash = [
{
"array_value" => 1,
"other_values" => "whatever"
},
{
"array_value" => 2,
"other_values" => "whatever2"
},
]
我试过delete_if
array_hash.delete_if{|a| a['inner_value'] }
但是它会删除数组中的所有数据。有什么解决办法吗?
试试这个:
array_hash.map{ |a| {'array_value' => a['array_value'], 'other_values' => a['other_values'] }}
我是一名优秀的程序员,十分优秀!