Could someone help me to create a JavaScript function that would turn the string below into an Object?
var structure = 'user.location.city';
When ran through the JavaScript function would return an object structured like this:
user: {
location: {
city: {}
}
}
I came up with the code below, but the object is messed up:
var path = structure.split('.');
var tmp_obj = {};
for ( var x = 1; x < path.length; x++ ) {
tmp_obj[path[x]] = {};
};
I don't know how to add the "city" Object to the "location" Object.