#Javascript string as json argument

1 messages · Page 1 of 1 (latest)

glass knoll
#

@grizzled star xTTLegend's Question:

**_```js
const myBigJsonObject = {
"somecategory": {
"test": "something",
"moretest": "moresomething"
},
"secondcategory": {
"okay": "nice"
}
}

const myString = "test";

console.log(myBigJsonObject.somecategory.myString) // Does not work


How can i use the `myString` to get something in a json object (`myBigJsonObject`)?
_**

In order to use the value of `myString` as a key to access a property in `myBigJsonObject`, you should use bracket notation instead of dot notation. Like this:

```js
console.log(myBigJsonObject.somecategory[myString]);

This will output "something".

grizzled star
#

wow