user3521579 user3521579 - 8 months ago 21
JSON Question

How to compare the data in JSON object to a variable?

Hi guys so I was wondering if it was possible to search content in a Json object with a variable?


var username = "name";

The json object Im getting from an api is in the following format:


The username is obviously different for everyone. I want to be able to get the id of the user and display it when the user enters their username in a text field.

var username ="somename";


That code above gives me undefined but if I put somename where username is then it works fine.


Use bracket notation to access property using a variable

//               -^-      -^-