File Under: Glossary

Hash

A hash, also known as an associative array, is a collection of data in which each piece of data has two components: a key and a value. Much like the hash at your local diner, JavaScript hashes go unordered: They’re not indexed by numbers. For example, if you wish to use JavaScript to put up a different GIF animation on your site every day of the week, you might throw all these animations into a hash associated to each weekday as a key. Then you would refer to the key day to invoke that day’s animation.

For example, in a normal array, you’d have:

  dinner[0] = "monkey brain";

  dinner[1] = "meatloaf";

But in a hash, you could use a string as the index:

  dinner["monday"] = "monkey brain";

  dinner["tuesday"] = "meatloaf";