Arrays

Array can hold an ordered set or list of data. It can hold any type of objects of data. Many different type of functions or actions can be done on an array.

Hashes

Hash can also hold collection of pair of information with a key and a value. The name is called a key, and it must be unique. You use the key to return the value paired to it.

Arrays and hashes can be written as following:

desired_array_name = ["Array" (string), 3 (number), false (boolean), 2.33 (float), [etc, {and_more}] (another array or hash)]

desired_hash_name= {"first_name" => "Andrew", "last_name" => "Kim", "age" => 28, "array"=> [etc], "hash" => {etc}}

The comparison and the difference

Arrays and hashes are both collections used to store and retrieve data. They both hold objects such as integers, floats, booleans, and strings. There are many differeces between the two. As you might have already noticed, the type of brackets that they use for their data is different. Hashes has no limits on storage so the data can be inserted however many times as one wishes to. Another differene between the two is that hashes hold a pair of data whereas arrays can hold a set of data. That means that hashes can hold a key and a value. The arrays just take a data. For example, hashes can hold personal information, like first name or last name and store the value for them. In the other hand, arrays can hold a list of names in a classroom. If one does not know which one is useful for what, hash can be used to look up an information faster due to its easier indexing mechanism. Lastly, another difference is that arrays can store another set of arrays within themselves. The picture below will simply differentiate the way of data can be stored in arrays and hashes.