I have an array containing a large number of contents
Names = ["one", "two", ......."forty"]
Now, I would like to loop through sections of the array. For example, from records 10 to 20, How can I go about this?
I tried this approach –
Names.each_with_index do |val,index|
break if index == 10
puts "#{val}"
end
In this way, I can print the first ten records. What should I do for getting next set of 10 names?
Any help is appreciated.
Cheers!
You can use
each_sliceto get successive sections of the array. For example: