How to delete a range of values from an array?

前端 未结 5 1969
走了就别回头了
走了就别回头了 2021-01-02 07:46

If array = [1, 2, 3, 4, 5, 6, 7, 8, 9], I want to delete a range of elements from array.

For example: I want to delete all elements with an index in th

5条回答
  •  遥遥无期
    2021-01-02 08:09

    Use slice!:

    Deletes the element(s) given by [...] a range.

    array = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    array.slice!(2..5)
    array #=> [1, 2, 7, 8, 9]
    

提交回复
热议问题