Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

108
Vistas
how to access object data within object

I have this:

const paymentIntents = await stripe.paymentIntents.list({
    stripeAccount: stripe_account
});

and it returns:

object: 'list',
  data: [
    {
      id: 'pi_...',
      object: 'payment_intent',
      amount: 2500,

now I have two problems. 1. I need to access amount. and 2. there is going to be dozens of records being returned, so I need to loop through all the results and actually add up the amounts. here's what I've tried so far:

console.log(paymentIntents.amount)
console.log(paymentIntents.data.amount)

neither of those worked. and i wouldn't even know how to loop thorugh all those results. How can i do this?

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

Be aware that if you expect to come close to the limit of 100 results for a list request, you should make sure to handle pagination, for example using the autopagination supported by stripe-node:

let total = 0
stripe.paymentIntents.list({limit: 5})
  .autoPagingEach(function(pi) {
    total += pi.amount
  });

Note that this structure requires iteration, and precludes the use of reduce-type solutions in the other answers. If your expected result set won't come close to the 100 item limit, then set your limit appropriately and don't worry about this.

about 4 years ago · Juan Pablo Isaza Denunciar

0

you can use reduce like this:

const paymentIntents = {object: 'list', data: [{
      id: 'pi_...',
      object: 'payment_intent',
      amount: 2500}, {
      id: 'pi_...',
      object: 'payment_intent_2',
      amount: 3500,
}]}
const amount = paymentIntents.data.reduce((previous, current, index, array) => {  
 const sum = current.amount + previous.amount; 
 return sum; 
});
about 4 years ago · Juan Pablo Isaza Denunciar

0

const paymentIntents = await stripe.paymentIntents.list({
    stripeAccount: stripe_account
});

const total = paymentIntents.data.reduce(
  (listTotal, line) => listTotal + line.amount,
  0
);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda