I need help accessing a string "key1.key2"
as properties of an object. For instance:
var obj = { key1 : {key2 : "value1", key3 : "value2"}};
var attr_string = "key1.key2";
The variable attr_string
represents attributes in a nested object that are connected by periods ("."
). This could be at any level of depth, such as "key1.key2.key3.key4..."
My goal is to use something like obj.attr_string
to retrieve the value of obj["key1"]["key2"]
, which would be "value1"
Can you advise me on how to accomplish this?