1

Consider the following code:

var obj = {};
obj.bar = 'w00p!';           //works
obj.foo.bar = 'there it is'; //throws error because bar is not set

Could you ever make obj.foo.bar = work if obj.foo is not set?

Is there an elegant way to set a deep variable in an object in JavaScript? In the same spirit as mkdir's -p option: mkdir -p a/deep/dir

2

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.