Is there a better way to retrieve values from a JSON file by matching key names? The current method I am using does not seem to work with nested keys, so any suggestions on alternative approaches would be appreciated.
// Sample .JSON file
{
"routes":{
"path":{
"register":{
"index": "register"
},
"login":{
"index": "login"
}
...
}
}
}
// Current solution(not working)
const paths = require(`../locales/en-US.json`)
const getByValueByKey = (getPath, value) => {
for (let key of Object.keys(getPath)) {
if (getPath[key] === value) {
return key;
}
}
}
getByValueByKey(paths, 'routes.path.login.index')//should return login