1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Rails]Arrayメソッド fromとto の使い方

Last updated at Posted at 2021-06-21

はじめに

Railsで使えるArrayメソッドのfromtoを使用したので備忘録として残しておきます。

使い方

1. from

fromは引数に指定した位置から配列の最後までの要素を配列として返します。

[0,1,2,3].from(2) 
=> [2,3]

2. to

toは引数に指定した位置まで要素を配列として返します。

[0,1,2,3].to(2)
=> [0,1,2]
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?