I have a JSON file that has:
{ "a": "letter a", "b": "letter b", "c": "letter c" }
When the user type in the textbox "b", how do I convert the string from the textbox into a key to access the "b" key in the JSON in JS?
I have a JSON file that has:
{ "a": "letter a", "b": "letter b", "c": "letter c" }
When the user type in the textbox "b", how do I convert the string from the textbox into a key to access the "b" key in the JSON in JS?
3
Answers
How about accessing the value from the user first and then accessing the value from object.
You can use the square bracket notation to access the value of a specific key in a JSON object in JavaScript:
For example:
Here’s the solution for a given problem:
App Structure:
app.js
fileindex.html
filedata.json
file