Created
June 14, 2018 09:22
-
-
Save Komock/01e25182149855e0245781068727163c to your computer and use it in GitHub Desktop.
Get value by string path
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
const some = {a: { bc: { de: 'hello'}}}; | |
const path = 'a.bc.de'; | |
let result = Object.assign({}, some); | |
path.split('.').forEach( part => { | |
console.log(result); | |
result = result[part]; | |
}); | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment