Access by index


#1

hi guys please help me :frowning: this is my code .

demo_array = [100, 200, 300, 400, 500] demo_array[300] print "demo_array"


#2

@pinkbutterfly,
With a google search

array element site:https://en.wikibooks.org/wiki/Ruby_Programming/Data_types
https://en.wikibooks.org/wiki/Ruby_Programming/Data_types

With

demo_array = [100, 200, 300, 400, 500]

you assign an Array of 5 elements to the variable demo_array

From now on if you use the variable demo_array
the Ruby-Interpreter will know you mean [100, 200, 300, 400, 500]

If you want to get the Value from the first-Element
you would use

print dem_array[0]

which will present the number Value 100