Is there a way to convert a dot notation string such as 'a.b.c.d' into an Object? And if the Object referenced doesn't exist, can we automatically create an empty one?
var str = 'a.b.c.d'
var obj = {}
// Now what?
function dotToObj(obj, str) {
// Code implementation needed here
obj[?] = obj[?] || {}
}
// In case the object doesn't exist, let's create an empty object.
var result = dotToObj(obj, str);
console.log(result)
// Expected Output:
Object {a: Object}
a: Object
b: Object
c: Object
d: Object
__proto__: Object
__proto__: Object
__proto__: Object
__proto__: Object