I have this function that tries to retrieve all the customer's emails in stripe:
const customers = await stripe.customers.list({
});
var customerEmail = customers.data[0].email;
console.log(customerEmail)
I am trying to return all the email addresses of the users from stripe. the problem is, when I log it, it only returns the first one, due to teh fact that I have data[0]. I need all of them, but i can't put it in a loop because what am i looping through. is there any way to do this properly?
The data property you are indexing is an array you can iterate through[1].
const customers = await stripe.customers.list({});
customers.data.forEach(customer => {
console.log(customer.email);
});