I have a return object like so:
Can you tell me how to access its properties?
I have tried many ways with Lodash too. But no luck yet.
Failure attempts:
t.config['type']
pick(t.config, 'type')
CodePudding user response:
Since the config
property is a serialized JSON string. You can work with it simply by deserializing it as follows
t.config = JSON.parse(T.config);
console.log(t.config.test);
However, if you have any control over how the object t
is provided to you, please (and I really mean please), fix and clean up that provider so you don't have nested, partially serialized objects. Otherwise, maintainability will suffer.
CodePudding user response:
Simply do...
const myResponse = JSON.parse(response.config);
console.log(myResponse.type);