[RUBY] Array

What is an array?

It is possible to manage multiple values ​​in order with one variable. The array is generated by enclosing it in square brackets [].

Example

fruits = ["apple","lemon","strawberry"]
puts fruits

# apple
  lemon
  strawberry
Is output

Operators that perform various operations on arrays are called array operators. If you want to add additional elements to the already generated array, use <<

fruits = ["apple","lemon","strawberry"]
fruits << "orange"
puts fruits

#The contents of the array["apple","lemon","strawberry","orange"]Next door
  apple
  lemon
  strawberry
  orange
Is output

To get the elements of an array

Extract using the number assigned to each element of the array called subscript. Subscripts start from 0 and increase in order.

You can get the element by specifying the subscript corresponding to the element you want to get. To get the array, enclose the array and the subscript of the element you want to get with square brackets [].

fruits = ["apple","lemon","strawberry"]
puts fruits[1]

#lemon is output

that's all.


Recommended Posts

Array
Array
[Java] array
[Ruby] Array
Java array
Array practice
Java array
java (array)
Java array
[Java] Array
Array practice 2
Java array
12 of Array
java array
[Java] Array
java array variable
About array multiplication
JavaScript array manipulation
[Java] Array notes
Array / list / map
Array is object
Ruby two-dimensional array
Studying Java-Part 7-Array
Ruby array manipulation
About Java Array List
[Java ~ Array ~] Study memo 4
Create path from array
Multidimensional array in Swift