Access data object properties inside an object

So I have the following piece of code:

const Menus = wp.api.models.Post.extend({
    url: wpApiSettings.root + 'fh/v1/menus/' + path,
});

const menus = new Menus();
console.log(menus);

menus outputs the following object:
enter image description here

How would I be able to access the data: { object and it’s properties? It looks like it’s an object inside an object.

When I do console.log(menus.attribute) that works fine, but console.log(menus.attributes.data) or even console.log(menus.attributes.success) just returns a undefined answer.

I tried doing the following:

console.log(menus.attributes['data'] also with a undefined answer.

All help is appreciated!

3 thoughts on “Access data object properties inside an object”

  1. Probably you have an async problem here. You can try console.log the result inside a callback function.

    For example you can try a similar approach like this :

    import axios from 'axios';
    
    async function getItems() {
      const response = await axios.get(SOME_URL);
      console.log('done', response);
      return response;
    }
    
    getItems().then(items => console.log('items: ', items))
    
    
    Reply

Leave a Comment