How to add named properties to a JavaScript array as if it were an object?

To add named properties to a JavaScript array as if it were an object, we can add them directly to the array with assignment.

For instance, we write

const myArray = [];
myArray.a = "Athens";

to define the myArray array and assign the a property of the array to 'Athens'.

We can do this because arrays are objects.