Suppose we are only given
var obj = {}; var propName = \"foo.bar.foobar\";
How can we set the prop
Here is a simple function to do that using reference.
function setValueByPath (obj, path, value) { var ref = obj; path.split('.').forEach(function (key, index, arr) { ref = ref[key] = index === arr.length - 1 ? value : {}; }); return obj; }