Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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.

console.log(cart.items)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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/

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading