Skip to content

Associative arrays in JavaScript

Also called dictionaries.

Associative arrays are not supported by default, but they can by:

  1. creating empty arrays
  2. adding elements to the array with named indexes

This procedure will convert the arrays into objects.

Example:

var person = [];
person["name"] = "John";
person["age"] = 39;

However, this procedure is not safe and not recommended. It is recommended to use objects instead of associative arrays.