user3521579 user3521579 - 1 year ago 59
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.

Answer Source

Use bracket notation to access property using a variable

//               -^-      -^-
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download