Say I have the following:
var a = '1',
b = 'foo';
How do I create an object using the above variables such that my object looks like this:
'1' => 'foo'
I’m trying to make this like an associative array. Furthermore, I want 1 to contain an array of objects. I have the variable that have the array of object; I just need to put it in 1.
Use an object literal:
or, if you want to create it from variables, create a new object then assign things.
JavaScript doesn’t care what type the data is.
bcan be an array as easily as a string. (And you can use an array literal where you have a string literal in the short version)