---
# System prepended metadata

title: Reading config vars

---

# 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";
}

```