- 论坛徽章:
- 0
|
带序号循环Hash
Ruby代码- 1.hash.keys.each_with_index do |key, index|
- 2. value = hash[key]
- 3. print "key: #{key}, value: #{value}, index: #{index}\n"
- 4. # use key, value and index as desired
- 5.end
- hash.keys.each_with_index do |key, index|
- value = hash[key]
- print "key: #{key}, value: #{value}, index: #{index}\n"
- # use key, value and index as desired
- end
复制代码 Ruby代码- 1.hash.each_with_index do |(key, value), index|
- 2. print "key: #{key}, value: #{value}, index: #{index}\n"
- 3. # use key, value and index as desired
- 4.end
复制代码 |
|