Skip to main content
Added a rebuttal to the 'no literals'
Source Link
Marc Thibault
  • 1.7k
  • 1
  • 13
  • 14

In javascript, associative arrays, keyed collections, hashes, ... whatever you want to call them, are not a special type. All the following are good.

a = {} a[3] = 15 a.b = "c" a['def'] = 'something' 

This code produces a single valid object with the properties you would expect. All of them. You can combine a conventionally indexed array and an associative array in one object.

As to declaring a whole bunch at once, the usual syntax is:

a = { 'key1' : 'val1', 'key2' : val2, key3 : val3, key4 : "val4" } 

In javascript, associative arrays, keyed collections, hashes, ... whatever you want to call them, are not a special type. All the following are good.

a = {} a[3] = 15 a.b = "c" a['def'] = 'something' 

This code produces a single valid object with the properties you would expect. All of them. You can combine a conventionally indexed array and an associative array in one object.

In javascript, associative arrays, keyed collections, hashes, ... whatever you want to call them, are not a special type. All the following are good.

a = {} a[3] = 15 a.b = "c" a['def'] = 'something' 

This code produces a single valid object with the properties you would expect. All of them. You can combine a conventionally indexed array and an associative array in one object.

As to declaring a whole bunch at once, the usual syntax is:

a = { 'key1' : 'val1', 'key2' : val2, key3 : val3, key4 : "val4" } 
Source Link
Marc Thibault
  • 1.7k
  • 1
  • 13
  • 14

In javascript, associative arrays, keyed collections, hashes, ... whatever you want to call them, are not a special type. All the following are good.

a = {} a[3] = 15 a.b = "c" a['def'] = 'something' 

This code produces a single valid object with the properties you would expect. All of them. You can combine a conventionally indexed array and an associative array in one object.