Associative arrays in JavaScript

Enrico Hochkoeppler Profile

By Enrico Hochkoeppler

Web Developer & TutoriaLibre Founder

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.

Found this helpful? Share the knowledge...

... or support this project to keep it alive!

Buy Me a Coffee

Previous

Arrays

Next

Math