+ 2
With arrays, do you HAVE to refer to the last or second to last item with -1?
I tried to call for the false by putting in 4 instead of - 1 like in the example, but it suddenly didn't work... why? arr = [5, "Dave", 15.88, false] puts arr[0] #5 puts arr[1] #"Dave" puts arr[4] #false
4 odpowiedzi
+ 14
The size of the array is 4
But the index starts at 0
So 0 is 5, ¹ is "Dave", 2 is 15.88 and 3 is false
To get false, use arr[3]
[Edit] fixed typo
+ 13
@AJ Oops, it was a typo. Fixed now, thanks
+ 2
Oh right I forgot, wait you mean the index starts at 0 right?
+ 1
thank you