Strings as keys of array

In javascript there are 2 type of arrays: standard arrays and associative arrays

  • [ ] – standard array – 0 based integer indexes only
  • { } – associative array – javascript objects where keys can be any strings

So when you define:

var arr = [ 0, 1, 2, 3 ];

you are defining a standard array where indexes can only be integers. When you do arr["something"] since something (which is what you use as index) is not an integer you are basically defining a property to the arr object (everything is object in javascript). But you are not adding an element to the standard array.

Leave a Comment