The term element mean a distinct object that is member of a set. This terminology originates from the mathematical set theory. It is used in computer science algorithms with the same meaning, for any kind of collections.
Arrays, be it classical indexed arrays, or more elaborate associative arrays are a data structure that represents the relation between a key (or index, in the case of indexed arrays) and a value.
The element is not the really value. The value alone is not sufficient: they have no identity, and two same values cannot be distinguished. Example:
string colour[] = { "red", "blue", "red" } // language with classical arrays
Array := {"title": "Doe", "author": "Doe"} // language with associative arrays
If the values would really be the elements, how would you understand "swaping two elements", for example the "red"
and the "blue"
? What's missing here to say which "red" you want to swap ? The key (or index) !
Now, it is not possible to give an accurate definition without considering mutablility:
If the elements are immutable, the combination key-value (or index-value) is a better candidate for being an element than the value alone. 0-red, 1-blue, 2-red are distinct elements.
If the elements are mutable, the combination key-value no longer defines correctly the element. In this semantic, if I change colour[1]
from "red" to "green", it's still the same element, but with a new value. Here, the element is the unique object associated with the key/index.