Skip to content

Instantly share code, notes, and snippets.

@theverything
Created January 20, 2015 01:17
Show Gist options
  • Save theverything/f8a52c42d0c9cd8b7afc to your computer and use it in GitHub Desktop.
Save theverything/f8a52c42d0c9cd8b7afc to your computer and use it in GitHub Desktop.
object edit
function edit(obj, key, value) {
if (!key) return obj;
var keys = key.split('.');
return keys.reduce(function (prev, next, i) {
if (keys.length === i + 1 && value !== undefined) {
prev[next] = value;
return obj;
} else {
return prev[next];
}
}, obj);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment