Last active
August 15, 2019 05:42
-
-
Save joladev/691cd1341008d04153e4632510ede3ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const setIn = (obj: Object, key: string, value: string): Object => { | |
const levels = key.split('.'); | |
const innerMostKey = levels.pop(); | |
const innerMost = { [innerMostKey]: value }; | |
const m = levels.reverse().reduce( | |
(acc, curr) => ({ | |
[curr]: acc, | |
}), | |
innerMost as Object | |
); | |
return Object.assign(obj, m); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment