0
Nested Arrays and hashes q
"What is the output of this code? arr = [5, [9, 4, 6], [8]] puts arr[1][0]" how do u get the out put 5? I tried running- assuming 5 is contained in location 0 in the 0 arr. puts arr[0][0] but once running it , result came back as 1
2 Antworten
+ 11
You'll use the square bracket notation only when you want to acess an array element. In this case, 5 is an integer. 😉
For example:
arr[0] = 5
arr[1] = [9, 4, 6]
arr[1][1] = 4
...
0
Result: 9