var data = {};
....
data[someprop][someotherprop] = 'bla bla'
I get
Uncaught TypeError: Cannot read property ... of undefined and Cannot set property of...
Yes, the object doesn’t have these properties ..yet, but I’m setting them in that line where I get the error lol. So what’s up with that?
if
somepropandsomeotherpropare variables, Richard D’s answer is correct, if they are hardcoded strings, you could write your code like this:if, however, they are values stored in variables, and you really – really want to cram everything into a single line, try something like this:
where window can be replaced by any object, if the
somepropvalue is itself a property of an object:Or jQuery objects, since your tag suggest you’re using jQuery:
Note: the jQuery example is not to be recommended, as the id selector is used twice on the same element. jQuery will scan the DOM-tree twice, so you’re better of storing your that
#formSelectelement in a variable somewhere.