Array သည် ordered list ဖြစ်ပါတယ်။ Item တွေကို နံပါတ် index နဲ့သိမ်းထားပြီး index က 0 ကနေစပါတယ်။ Shopping list, users list, scores list စတာတွေသိမ်းဖို့ အသုံးများပါတယ်။
ruby
fruits = ["Apple", "Banana", "Cherry"]
puts fruits[0]
fruits << "Durian"
puts fruits.last
puts "Total fruits: #{fruits.length}"
fruits.each_with_index do |fruit, index|
puts "#{index + 1}. #{fruit}"
endfruits[0] က ပထမ item ကိုယူပါတယ်။ << က array အဆုံးမှာ item ထည့်ပါတယ်။ .each_with_index က item နဲ့ index နှစ်ခုလုံးကို loop ထဲပေးပါတယ်။
You should see
Apple Durian Total fruits: 4 1. Apple 2. Banana 3. Cherry 4. DurianInfo
Array index က 1 မဟုတ်ဘဲ 0 ကစတာ သတိထားပါ။