---
# System prepended metadata

title: Reading env vars

---

# Reading env 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 get = (obj, path) => {
    
    if(obj !== null || typeof obj !== 'object') {
        return null;
    }
    
    if(!path) {
        return null;
    }
    
    const props = path.split('.');
    
    let value = obj;
    for(let i = 0; i < props.length; i++) {
        const prop = props[i];
        value = value[prop];
        
        if(value === undefined) {
            value = null;
            break;
        }
    }
    
    return value;
    
}


```