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

173
Vistas
Console log the value of item in array

I have this array and I want to console log item value. How can I do that? I got this array from MongoDB. I would appreciate any help.

{
"_id" : "61462a7bf3c0be993bcfdc3e",
"item": "journal",
"qty": 25,
"size": {
"h": 14,
"w": 21,
"uom": "cm"
},
"status": "A"
}

Edit: I looked in MongoDB documentation and found the solution. Thanks to everyone who answered.

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

0

I think you can simply access the key from the object like this:

const obj = {
"_id" : "61462a7bf3c0be993bcfdc3e",
"item": "journal",
"qty": 25,
"size": {
"h": 14,
"w": 21,
"uom": "cm"
},
"status": "A"
}

console.log(obj.item);

Another way could be to find out the keys and iterate over them if keys are dynamic in nature:

const obj = {
"_id" : "61462a7bf3c0be993bcfdc3e",
"item": "journal",
"qty": 25,
"size": {
"h": 14,
"w": 21,
"uom": "cm"
},
"status": "A"
}

const keys = Object.keys(obj);

keys.forEach(key => console.log(`Key is ${key} and the value is ${JSON.stringify(obj[key])}`))

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can try:

Object.entries(YOUR_OBJECT_NAME).filter(val=>val[0] === "item")

You will get back an array of key and value pair. You can then console.log your value.

Easier solution is that you directly determine your key. If you know what is the name of your key then you can do:

console.log(YOUR_OBJECT_NAME.item)
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