Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get object array generated by axios get

(async() =>{
    const axios= require('axios');
    const response = await axios("https://graph.facebook.com/v13.0/110524034851999/feed?limit=3&access_token=×××××××");
    const data = response.data;
    console.log(data);
    console.log(data[0]);
})();

Above is the code I am using to get json from Facebook API I am getting an object as below

data: [
    {
      created_time: '2022-04-14T14:01:45+0000',
      message: 'How to make jw',
      id: '...'
    },
    {
      created_time: '2022-04-14T14:01:19+0000',
      message: 'Testing',
      id: '....'
    },
    {
      created_time: '2022-04-14T01:51:41+0000',
      message: 'Enriqueta',
      id: '.....'
    }
  ],

I am not able to get the data from object using data[0] which should return me first object but it’s giving me undefined error how can I get the message which is on first array of data object from the above json?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

replace

console.log(data[0]);

with

console.log(data.data[0]);

maybe?

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading