Spent quite some time and googled but I can't seem to achieve this in Javascript:
PHP:
$items['01A']['price'] = "$30";
$items['01A']['description'] = "Description1";
$items['02B']['price'] = "$60";
$items['02B']['description'] = "Description2";
Output:
Array
(
[01A] => Array
(
[price] => $30
[description] => Description1
)
[02B] => Array
(
[price] => $60
[description] => Description2
)
)
Well, I can, like so:
var obj = {
'0113A5' : {
'price' : '1200',
'discount' : '5'
},
'0213A5' : {
'price' : '1800',
'discount' : '0'
}
};
... but assigning values inside a look isn't possible because this:
obj['0313A5']['price'] = "2000";
//or
obj.0313A5.price = "2000";
... throws an error.
obj['0313A5']['price'] = "2000";is perfectly valid... what's the error you see?TypeError: Cannot set property 'price' of undefined