Access to hash in Multidimensional Arrays


#1

Hello! Below I added my code. I’m intresting how I can get to access in [2] index ( it’s [“under” => “citty”, “why” => 5]) and it’ll show me only keys. Or maybe it’ll show me only values or the first letter of first or second key.

numbers = [[1, 2, 3, 4, 5], ["fully", "great"], ["under" => "citty", "why" => 5]] 

p numbers[1]
p numbers[1][0]
p numbers[1][0][4]
p numbers[0][2]
p numbers[2][0]

Thank you for answer :wink:


#2

You need to write the hash as a hash using {}.


#3

Thanks for answer but I wanted to know how get to access by hash when it is part of a multidimensional array


#4

It’s not a hash if it is not written as one.

[{key => value, key => value}]

#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.