0

So Im trying to print specified value from axios get response but its still undefined

here is response.data log

and here is specified response.data.id & response.data.ID log

why is this happening?

Here is code

            const response = await axios.get(`${apiurl}/get/id/${id}`);
            console.log(response.data);
            console.log(response.data.id);
            console.log(response.data.ID);
  • 1
    because `response.data` obviously is an `array`. And an `array` does have neither an `id` nor an `ID` property. Try `response.data[0].ID` instead ... – derpirscher Nov 23 '22 at 23:10
  • Fix your API to not return an array for requests that should only return a single object – Phil Nov 23 '22 at 23:11

0 Answers0