LoginSignup
0
0

More than 1 year has passed since last update.

配列 の 基本的な扱い方

Posted at

目的

  • 配列の生成方法、使い方を理解する

ポイント

  • 配列とは データの塊のこと
  • 配列のメリットは、要素をまとめて処理できること
  • 要素の取得は、添字(index)を指定する

書き方の例

array = Array.new  #配列の生成
array.push("apple", nil, 12, true) #要素の追加
p array[-1]
p array[0]

array[1] = "orange"  #2番目の要素を文字列「orange」に更新
p array

array.delete_at(2)  #3番目の要素を削除
p array

~実際の表示~
true
"apple"
["apple", "orange", 12, true]
["apple", "orange", true]

注意するポイント

  • puts で配列を出力すると、[]で表示されない
  • index は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