How to select array elements in a given range in Ruby?

前端 未结 5 1219
傲寒
傲寒 2021-02-05 03:21

I have an array with let\'s say, 500 elements. I know I can select the first 100 by doing .first(100), my question is how do I select elements from 100 to 200?

5条回答
  •  猫巷女王i
    2021-02-05 04:02

    You can do it like this:

    array[100..200] # returns the elements in range 100..200
    # or
    array[100,100] # returns 100 elements from position 100
    

    More Information

提交回复
热议问题