Array vs Hash: The Difference

7.11.15


The easiest way to explain the difference between arrays and hashes is by first explaining them separately. Think of an array as just a list of items, such as a basic grocery list. An array is just a collection of data thats arranged in some sort of order. A hash is a little more specific then that. Hashes are a collection of specific keys that all have a value paired to it. The key must be unique to one another and must be given a value that you want to call on. Think of it as a collection of pairs of information. So instead of thinking of it as a basic grocery list, think of it as a more specific list. It will tell you to get not just meat but what type of meat you want.

blogs