Search code examples
node.jsreststripe-paymentshttpresponse

Node.json response


I am using stripe calls in node JS.

const balance = await stripe.balance.retrieve**********************;

These are the replies. **first try **

console.log('successful', balance)

returns

successful {object: 'balance', available: [ { amount: 5580, currency: 'aud', source_types: [Object] } ], livemode: true, pending: [ { amount: 0, currency: 'aud', source_types: [Object] } ]}

second try

console.log('successful',balance.amount);

returns successful [ { amount: 5580, currency: 'aud', source_types: { card: 5580 } } ]

How do I access only the amount within the []?

I have tried multiple combinations

  const available = await balance.available;
 console.log('successful',balance.available);
 console.log('successful',balance.available[1]);
 console.log('successful',available.amount);

None have so far worked.


Solution

  • You have to print as belove.

    console.log('successful', balance[0].amount)