# Reading config vars Write a method to read configuration values from a configuration object based on a key Example of keys as input: ``` "profile.setting.showImage" "home.showAnalytics" ``` # Code ```javascript= const config = { profile: { setting: { showImage: false, noOfEnemies: 0, nameOfChild: '', } } }; const readConfiguration = (key, configObj) => { let testedObj = configObj; const stringsArray = String.split(key, '.'); stringsArray.forEach((key) => { if(testedObj && (testedObj[key] || testedtestedObj[key] === 0)) { testedObj = testedObj[key] } else { testedObj = null; } //configObj[key] ? testedObj = configObj[key] : {testedObj = null; return} }) if (testedObj) return testedObj; else return "Configuration value not found"; } ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up