I have an object called themesData
:
var themesData = {}
themesData.a = { key: "value" };
themesData.b = { key: "another value"};
...and I want to access one of the members by its name. I get a string which contains either "a" or "b" and I want to get the appropriate member's value.
I'd be happy to get some help on that.
Use the member-access operator ( . ) between the object variable name and the member name. If the member is Shared, you do not need a variable to access it.
Answer: Use the Square Bracket ( [] ) Notationnotation, like obj. foo , and the square bracket ( [] ) notation, like obj[foo] . Where the dot notation is easier to read and write, the square bracket notation offers much more flexibility since the value between the brackets can be any variable or expression.
We can use the jQuery library function to access the properties of Object. jquery. each() method is used to traverse and access the properties of the object.
themesData["a"].key
does what you need and is equivalent to themesData.a.key
, still the "array index style" notation allows you to dynamically generate index names.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With