Reputation: 736
Below is the theJson string which I have converted to object by JSON.parse
var clientScopeJson={"cl1":{"List":"rwe","urlList":["nclsdlc","alkdcjla"]}};
JSON.hasOwnProperty(id) returns as true but JSON.id gives undefined:
id = "cl1"
//scope = JSON.parse(clientScopeJson);
console.log(clientScopeJson);
clientId = "cl1";
exists = clientScopeJson.hasOwnProperty(clientId); // This returns as true
console.log(exists);
scopeList = clientScopeJson.clientId;
console.log(scopeList);
Upvotes: 0
Views: 45
Reputation: 1045
If you want to access key that is saved in variable, you can access it like this
const clientId = "cl1";
const scopeList = clientScopeJson[clientId];
If you try to use it with dot, you are trying to access 'clientId' key.
Upvotes: 2