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.

[Ruby] indexメソッド

Posted at

##はじめに
indexメソッドという便利なメソッドを見つけたので記事に残しておきます。

##indexメソッド
indexメソッドはある要素が配列のどこにあるか調べる際に便利です。

例えば3が配列のどこにあるか知りたい場合

array = [3, 2, 4, 1]
array.index(3)
=> 0

上記のように引数にどこにあるか調べたい要素を渡すと、インデックス数で配列のどこの位置にあるかを教えてくれます。

インデックス数で示されるので3は0で返ってきます。

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