Forum: Ruby on Rails each_with_index. Can you start at a desired index position?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Chris R. (Guest)
on 2006-05-12 19:19
When using array.each_with_index how do you start at a desired index

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

Brian B. (Guest)
on 2006-05-12 21:41
(Received via mailing list)
Here's one way.

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

Brian B.
This topic is locked and can not be replied to.