0
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.

要素の最後を求める時

Posted at

◼️ famiry = ["suzuki", "takurou", "gou",・・・・ "qiita"]
例えば上記の様な配列があったとする。最後の要素だけを取り出す時、suzuki 君から順に最後まで数えてqiita君の順番が98番だった時、puts famiry[98] と書き出力するのはそごくめんどくさい。

◼️ こんな時、こんな問題を解決するのが [配列の要素数 -1]を使うこと。
書き方: famiry[famiry.lenght -1 ]
     puts famiry

上記の様な書き方を行うことで全体の要素数から最後の値ふだけを出力できる。そして、数えるみたいなめんどいことはやらなくておくなる。

今日の投稿は以上です。

wagaでした!

0
0
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
0
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?