Reputation: 1428
So I thought I was crazy, and I may be but this seems pretty simple. Say I have this bit of code:
let a = {};
a.b.c.d.e.f.g = 'Something Awesome';
Now you can imagine the if-check nightmare that would have to take place to see if each level exists. And even if I had a fancy looping way to do it, someone else has had to think this up.
I think CoffeeScript had something like this, but I can't seem to find anything on it. I was also wondering if there was an ECMAScript6 or lodash way of doing the same type of thing?
Maybe something like:
set(a, b, c, d, e, f, g, 'Something Awesome');
And in that case even:
set(a, b, c, d, {e: {f: {g: 'Something Awesome'}}});
But the last option would wipe out anything that may exist in e
, f
, and g
.
Upvotes: 0
Views: 50