Each_with_index. Can you start at a desired index position?

When using array.each_with_index how do you start at a desired index
position?

I can do it like this, but its not very clean and doesnt seem efficient
:

desired_index_start = 20
array.each_with_index do |value,index|
next if index<desired_index_start
end

Thanks
Chris

Here’s one way.

array[20…-1].each_with_index do |value,index|

end

Brian B.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs