Skip to content

Instantly share code, notes, and snippets.

Last active November 9, 2021 17:46
What would you like to do?
Setting a deep JSON property with one call, a answer to a question on StackOverflow that was deleted before I could post it
function deepSet(keys, value) {
return keys.split('.')
.reduce((acc, current) => ({
[current]: acc
}), value);
//You can use it like this:
console.log(JSON.stringify(deepSet('', 100)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment