I try to dynamically step in depth inside an object. The object children is unknown and should instead be used from a string.
I hope you can see below what I try to do. I've comment out the part where I can't figure out a solution.
var global_object = {};
function populate(id, text) {
let parts = id.split('/');
for(let key in parts) {
let part = parts[key];
// global_object['this']['is']['a']['long']['url'] = text;
console.log(part);
}
}
populate('this/is/a/long/url', 'My text');
The results may be something like this:
this: {
is: {
a: {
long: {
url: "My text"
}
}
}
}
https://jsfiddle.net/2f6kue74/
ES6 solutions are accepted as well