The pushd and popd functions use a string variable to hold a list of directories and manipulate the list with the string pattern-matching operators. Although this is quite efficient for adding or retrieving items at the beginning or end of the string, it becomes cumbersome when attempting to access items that are anywhere else, e.g., obtaining item N with the getNdirs function. It would be nice to be able to specify the number, or index, of the item and retrieve it. Arrays allow us to do this. 
An array is like a series of slots that hold values. Each slot is known as an element, and each element can be accessed via a numerical index. An array element can contain a string or a number, and you can use it just like any other variable. The indices for arrays start at 0 and continue up to a very large number. So, for example, the fifth element of array names would be names. Indices can be any valid arithmetic expression that evaluates to a number greater than or equal to 0.
There are several ways to assign values to arrays. The most straightforward way is with an assignment, just like any other variable:
names=alice names=hatter names=duchess
This assigns hatter to element 0, duchess to element 1, and alice to element 2 of the array names.
Another way to assign values is with a compound assignment:
names=(=alice =hatter =duchess)
This is equivalent to the first example and is convenient for initializing an array with a set of values. Notice that we didn’t ...