What Is an Associative Array?

An associative array is an array with a special indexing method. Not only can it be indexed by an integer, it can also be indexed by a string or other type of value (except NULL).

An associative array is an array with a special indexing method. Not only can it be indexed by an integer, it can also be indexed by a string or other type of value (except NULL).
Chinese name
Associative array
Foreign name
associative array
Definition
An array with a special indexing method
Include
Scalar data
Element-specific order
no
Associative arrays are similar to arrays and consist of fields and methods with names as keys.
It contains scalar data, which can be selected individually using index values. Unlike arrays, the index value of an associative array is not a non-negative integer but an arbitrary scalar. These scalars are called Keys and can be used later to retrieve the values in the array. [1]
The elements of an associative array do not have a specific order, you can think of them as a set of cards. The top half of each card is the index and the bottom half is the value. [1]
The object of JavaScript is essentially an associative array.
Associative array usage in Perl:
  % ARRAY = (key1, value1, key2, value2, key3, value3);
or:
  % ARRAY = (
 key1 => value1,
 key2 => value2,
 key3 => value3
 );
One KEY corresponds to one VALUE.

IN OTHER LANGUAGES

Was this article helpful? Thanks for the feedback Thanks for the feedback

How can we help? How can we help?