You are really close, but parenthesis notation will not process points for you (it cannot - points are perfectly valid characters for property names). You have to do it yourself:
function set(path, change){ var privateObject = { a: 'a', b: 'b', c: { d: 'd', e: 'e' } }, index, parts, obj; parts = path.split("."); obj = privateObject; if (parts.length) { index = 0; while (index < parts.length - 1) { obj = obj[parts[index++]]; } obj[parts[index]] = change; } return privateObject; }
Live demo
I discarded this, it was not more efficient compared to older machines, and I did not investigate failure modes, but you understood: divide the path that you point to, then use each component of the page.
source share