I currently have this:
cart = [{"40"=>[{"size"=>"1", "count"=>1, "variation"=>nil, "style"=>"3"}]}, {"40"=>[{"size"=>"2", "count"=>1, "variation"=>nil, "style"=>"3"}]}]
How do I search this array and find out if "40" exists?
Use Enumerable#any:
item_in_cart = cart.any? { |item| item.has_key?("40") }
#=> true / false
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With