Home > other >  Can't access property from JavaScript object
Can't access property from JavaScript object

Time:09-17

I need to access properties from this object, but I am getting undefined.

I tried use JSON stringify and parse but without success.

console.log('ress', response.data);
console.log('ress data', response.data.url);
console.log('ress key', response.data.key);

output:

ress {"url":"my url","key":"my key"}
ress data undefined
ress key undefined

CodePudding user response:

Probably your response.data object is a string, in this case you have to parse it into a JSON object to be enable to access the properties.

object = JSON.parse(response.data);
console.log('data url', object.url);
  • Related