Sarangi Nath
Sarangi Nath

Reputation: 7

How to fetch id in data from Array?

  [
   {
      id: 9222,
      amount: 7,
      customer: [Object],
      plan: 9554,
      status: 'active',
      created_at: '2021-01-30T18:49:35.000Z'
    }
  ]

id: response.data.id tried like this,but getting undefined.

Upvotes: 0

Views: 258

Answers (2)

codemonkey
codemonkey

Reputation: 7905

Your data is an array. So the first thing you should do is decide which element of the array you want to get id for. Let's say you want the first element, then you would access it like so:

data[0].id

Also, I'm not sure where you got the response part in your question, for that we would need to see more of your code.

Upvotes: 1

kunal panchal
kunal panchal

Reputation: 798

if i am not mistaken to understand your requirement you want to fetch the id from the array from the response this way response.data[0].id if the response is an array then you will need to specify the index for the array

Upvotes: 0

Related Questions