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 1 year has passed since last update.

【Ruby】複数の配列を同時にループさせたいときはzipメソッドを使う

Last updated at Posted at 2021-12-22

##zipメソッド
複数の配列を同時にループされられる。

# 各配列の要素がインデックス0から取り出されて配列になる
array1 = [1, 2, 3]
array2 = [4, 5, 6]

p array1.zip(array2)
# => [[1, 4], [2, 5], [3, 6]]
@articles = ['article1', 'article2', 'article3']
@authors = ['kato', 'yamada', 'suzuki']

@articles.zip(@authors) do |article, author|
  puts article
  puts author
end

# => [["article1", "kato"], ["article2", "yamada"], ["article3", "suzuki"]]

0
0
1

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?