FAQ: Data Structures - Introduction to Hashes

This community-built FAQ covers the “Introduction to Hashes” exercise from the lesson “Data Structures”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Learn Ruby

FAQs on the exercise Introduction to Hashes

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Defining Hashes.

I understand a hash is collection of key-value pairs or a collection of keys along with their corresponding values. However, is it fair to also say that a hash is an advanced or varied form of an array where, instead of using integer values as indices to elements, the hash can take on any data type as an index to point to its values.

I’m familiar with arrays from old programming classes in college but completely new to hashes and am curious to see if my understanding of this concept is correct. Is there anything wrong in my understanding above?

Thanks for the response.

Hashes are sometimes known as “associative arrays.”, but are more frequently described as like a dictionary. Yes, it is right to say that arrays use integers as an index while hashes can use any type for its keys, which then identify values.

You could say that indexing is done by key, as is done in the linked reference, although the term “index” isn’t used with hashes as often as it is with array, since they are a collection of key-value pairs. Hashes and arrays are different data structures, so it can be useful to differentiate the associated terminology and keep things clear.

1 Like