Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
No puedo obtener el valor del objeto que quiero
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)] }

Aquí quiero llegar a los datos que están en cart.items.item._id pero devolvieron indefinidos.

 '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' }

Puedo llegar aquí como puede ver con el comando que escribí en la siguiente línea pero no pude llegar a _id.

consola.log(carrito.artículos)

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

cart.items.item no es válido. Sus items son un objeto que tiene una clave '618530ebdf45a7e949f085ef', por lo que deberá hacer algo como:

 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 Report

0

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

Salida: 618530ebdf45a7e949f085ef

Explicación: https://www.javascripttutorial.net/object/convert-an-object-to-an-array-in-javascript/

about 4 years ago · Juan Pablo Isaza Report

0

Creo que te falta el vínculo entre artículos y artículo.

Para acceder a lo que está buscando, debe acceder a esos datos a través de cart.items['61879cc4978daa8f84a779c4'].item._id

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!