Let’s say I have a JSON file like so (char_table.json):
{
"char_285_medic2": {
"name": "Lancet-2",
"description": "Restores the HP of allies and ignores the Deployment Limit, but has a long Redeployment Time",
"canUseGeneralPotentialItem": false,
"canUseActivityPotentialItem": false
},
"char_291_aglina": {
"name": "Angelina",
"description": "Deals Arts damage and Slows the target for a short time",
"canUseGeneralPotentialItem": true,
"canUseActivityPotentialItem": false
},
"char_2013_cerber": {
"name": "Ceobe",
"description": "Deals Arts damage",
"canUseGeneralPotentialItem": true,
"canUseActivityPotentialItem": false,
},
...
}
I currently only have the "name" varible, and I want to find the path of the object containing that exact "name" (example: name = "Angelina"
would return char_table.char_291_aglina
| name = "Ceobe"
would return char_table.char_2013_cerber
). How can I exactly do that using javascript?
2
Answers
Try this recursive re-usable function
Usage: