4
1

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 5 years have passed since last update.

Rubyで配列や文字列での末尾のインデックス指定

Posted at

配列や文字列の最後の文字を取得したいときは負のインデックス値を使用する.

  > a = [1 2 3 4 5]
  > s = "string"
  > a[-1] # => 5
  > s[-1] # => g
 

なんども忘れてるので覚え書き

4
1
2

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
4
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?