I am trying to key values from an JSON file by matching key names, but it does not work with nested keys, maybe not the best way to load date this way(if there are better ways to do this let me know).
// .JSON file
{
"routes":{
"path":{
"register":{
"index": "register"
},
"login":{
"index": "login"
}
...
}
}
}
// 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