简体   繁体   中英

access variable data from function node.js

I have this:

    const customers = await stripe.customers.list({
    email: 'email@email.com',
  });

  console.log(customers)

I want to access the id of the customer, so my initial thought was:

console.log(customer.id) 

however, it does not work. It says undefinied. the way the customers are getting returned is like so:

    {
  object: 'list',
  data: [
    {
      id: 'sub_id',
      object: 'subscription',

so i want to access customers.id if possible. how can i do this?

If you ever only get one customer returned:

console.log(customers.data[0].id);

If there are multiple:

for (const idData of customers.data){
    console.log(idData.id)
}

Make sure to check out iterations

EDIT:

Also make sure to check out working with objects

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM