I have made a js file in which data is being fetched from js file and the values are stored in a request object. Example of JSON file
{
"name": "ABC",
"age": 20
}
I want to display the value of name using variable name. I want something like this.
var x = "name";
var req = JSON.parse(request.responseText);
console.log(req.x);
But the above statement displays undefined. Any solutions?