Possible to access the index in a Hash each loop?

后端 未结 2 1363
悲哀的现实
悲哀的现实 2021-01-30 02:35

I\'m probably missing something obvious, but is there a way to access the index/count of the iteration inside a hash each loop?

hash = {\'three\' => \'one\',          


        
2条回答
  •  长情又很酷
    2021-01-30 03:11

    If you like to know Index of each iteration you could use .each_with_index

    hash.each_with_index { |(key,value),index| ... }
    

提交回复
热议问题