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

配列の要素を配列のindexとして使う

Posted at

配列の要素を別の配列のindexとして使えることが分かったのでメモ。

Usage

numbers = [0, 1, 3, 2, 4, 6, 1, 2, 4, 6]

array = []
p array #> []

配列numbers[0]の要素をindexにして、配列array[0]に要素を追加する

# numbers[0]の要素は0なので、array[0]となる
array[numbers[0]] = 10

p array[numbers[0]] #> 10
p array[0] #> 10

ハッシュもできる

subject = ["english", "math", "science"]
point ={}

point[subject[0]] = 98

p point #> {"english"=>98}
p point[subject[0]] #> 98
p point["english"] #> 98

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?