I can't get the object value that i want

Cart {
  items: {
    '618530ebdf45a7e949f085ef': { item: [Object], qty: 1, price: '50' }
  totalQty: 1,
  totalPrice: 50,
  add: [Function (anonymous)],
  reduceByOne: [Function (anonymous)],
  removeItem: [Function (anonymous)],
  generateArray: [Function (anonymous)]

I want here to reach the data that in cart.items.item._id but it returned undefined.

  '61879cc4978daa8f84a779c4': {
    item: {
      _id: '61879cc4978daa8f84a779c4',
      name: 'Emre',
      description: 'Doe',
      price: '77',
      color: [Array],
      stok: '88',
      sales: '0',
      img: 'e23cae42dcac7a435ec5e5586e3522c4.jpg',
      category: [Array],
      createdAt: '2021-11-07T09:30:44.862Z',
      slug: 'emre',
      __v: 0
    qty: 1,
    price: '77'

I can reach here as you see with the command that i wrote the following line but could not reach _id.


>Solution :

Try: console.log(Object.keys(this.cart.items)[0]);

Output: 618530ebdf45a7e949f085ef

Explanation: https://www.javascripttutorial.net/object/convert-an-object-to-an-array-in-javascript/

Leave a Reply