0

I'm trying to fetch the name of item which is inside items object, But maybe because of the id in-between those two I'm unable to do so.

I followed many previous anwwers here but couldn't find any help from them. Thats why I'm posting this.

I'm getting the whole order data when I console.log(order)

Order

{
  paymentType: 'COD',
  status: 'order_placed',
  _id: 60f5829e66e3683b682d45c6,
  customerId: 608d71cce87e0226b0efeb32,
  items: {
    '5eee66c4a27a66807cf2bea5': { item: [Object], qty: 3 },
    '5eee66cfa27a66807cf2bea6': { item: [Object], qty: 2 },
    '5eee6717a27a66807cf2bea8': { item: [Object], qty: 2 },
    '5eee6671a27a66807cf2be10': { item: [Object], qty: 1 },
    '5eee66a5a27a66807cf2bea4': { item: [Object], qty: 2 }
  },
  phone: '07123567897',
  address: 'New address',
  createdAt: 2021-07-19T13:48:14.792Z,
  updatedAt: 2021-07-19T13:48:14.792Z,
  __v: 0
}

And item are inside items which looks something like this when I do console.log(order.items)

{
  '5eee66c4a27a66807cf2bea5': {
    item: {
      _id: '5eee66c4a27a66807cf2bea5',
      name: 'Chocoholick Delight',
      image: 'Chocoholick Delight.jpg',
      price: 399,
      size: '1 pound',
      description: 'Cocoholics Delight is a delicious cake',
      categoryId: '60d7ea88fa019788bf588bd9'
    },
    qty: 3
  },
  '5eee66cfa27a66807cf2bea6': {
    item: {
      _id: '5eee66cfa27a66807cf2bea6',
      name: 'Elite Happiness',
      image: 'Elite Happiness.jpg',
      price: 499,
      size: '1 pound',
      description: 'Bombastic choco filled creaminess designed with mouth-watering Rochers on top.',
      categoryId: '60d80198f84f2a96ffd9012b'
    },
    qty: 2
  },

Now I want to get the name which is inside the item.

When I do console.log(order.items.id) I get undefined. How can I access the name.

If you notice Every items have id which is same as item id. I'm confused there that how to get inside that items id.

Thank you for looking us the question.

Ross
  • 11
  • 1
  • 3

0 Answers0