After an extensive search online yielded no results, I decided to seek assistance here.
This is what I have managed to gather so far:
- JSON
I possess a JSON file containing various lists of words that require retrieval based on user input. The structure appears as follows:
{
"length": 10,
"targetWords": {
"SOME_NAME": [
{
"words": [
"xyz",
"xyz",
"xyz",
"xyz",
"xyz",
"xyz",
"xyz",
"xyz",
"xyz",
"xyz"
]
},
{
"text": "Some example text",
"letter": "X",
}
],
}
- localStorage input
A prompt asks the user to select an option and stores the answer in a variable known as "userInput".
userInput = localStorage.getItem("something")
- The JSON data is fetched and assigned to a variable (leveraging Phaser Framework)
TARGET_SOUNDS_DATA = this.game.cache.getJSON('targetSounds')
My current goal is to extract the values from within. I can achieve this by following this approach:
TARGET_SOUNDS_WORDS_ARRAY = TARGET_SOUNDS_DATA.targetWords.SOME_NAME[0].words
However, when attempting to utilize the user's response/input like so:
TARGET_SOUNDS_WORDS_ARRAY =TARGET_SOUNDS_DATA.targetWords.userInput[0].words
Only undefined is returned.
It is evident that I am making a mistake, but where?
Any form of assistance or hints would be greatly appreciated! Thank you for your time!
Best Regards, J