Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Set nested object properties using dot notation with value
- * */
- const setNested = (obj, path, val) => {
- const keys = path.split('.');
- const lastKey = keys.pop();
- const lastObj = keys.reduce((obj, key) =>
- obj[key] = obj[key] || {},
- obj);
- lastObj[lastKey] = val;
- };
Add Comment
Please, Sign In to add comment