Array To Hash Ruby

[Solved] Array To Hash Ruby | Basic - Code Explorer | yomemimo.com
Question : array to hash ruby

Answered by : oldfashioned-otter-tc269hlqxfmy

# array = [["a", 1], ["b", 2], ["c", 3]]
array = [[:a, 1], [:b, 2], [:c, 3]]
# convert array to hash
hash = Hash[array]
puts hash
# Stdout/output:
# {:a=>1, :b=>2, :c=>3}

Source : | Last Update : Sun, 05 Jun 22

Question : ruby hash from array

Answered by : nguyen-quang-huy

Hash['key1', 'value1', 'key2', 'value2']
# => {"key1"=>"value1", "key2"=>"value2"}

Source : | Last Update : Mon, 06 Jun 22

Answers related to array to hash ruby

Code Explorer Popular Question For Basic