[英]ruby array with arrays how to get the array number when iterating over each of them and searching by number
if I get from params something like a 165. and this is number contains in array number 3 of 9. how to get this number of the array?如果我从 params 得到类似 165 的值。这是数组中第 3 个数组中包含的数字,共 9 个。如何获得数组的这个数字?
range = 50..450
cutter = range.last/50
b = range.each_slice(range.last/cutter).to_a
b #=> [[50, 51,..., 99],..., [400, 401,..., 450]]
How to get it?如何获得?
The array method you want is find_index
.您想要的数组方法是
find_index
。 I think this will do what you want:我认为这会做你想做的:
b.find_index {|a| a.include?(165)}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.