Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

160
Vistas
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)

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

cart.items.item is not valid. Your items is an object, that has a key '618530ebdf45a7e949f085ef', so you would need to do something like -

cart.items['618530ebdf45a7e949f085ef'].item._id

const cart = {
  items: {
    '618530ebdf45a7e949f085ef': { item: {_id: '123456'}, qty: 1, price: '50' }
  },
  totalQty: 1,
  totalPrice: 50,
 
}

console.log(cart.items['618530ebdf45a7e949f085ef'].item._id)

about 4 years ago · Juan Pablo Isaza Denunciar

0

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/

about 4 years ago · Juan Pablo Isaza Denunciar

0

I believe you are missing the link between items and item

To access what you are looking for you should reach that data via, cart.items['61879cc4978daa8f84a779c4'].item._id

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda