Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

163
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda