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

104
Vistas
How to get to item in object with Object.keys

I have been starting to look at javascript objects, and I have found the format that looks like this.

var obj = {
        prop1: 5,
        obj2: {
          prop1: [3, 6, 3],
          prop2: 74,
          4_3: {
            str: "Hello World"
          }
        }
      };

My question is. How do I get the console to say the string?

I have tried something like this:

console.log(obj.obj2[Object.keys(obj.obj2)[2]].str);

But it didn't work.

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

0

I'm not change the input this time

var obj = {
  prop1: 5,
  obj2: {
    prop1: [3, 6, 3],
    prop2: 74,
    4_3: {
      str: "Hello World"
    }
  }
};

console.log(obj.obj2[Object.keys(obj.obj2)[0]].str);
about 4 years ago · Juan Pablo Isaza Denunciar

0

Why not just reference?

var obj = {
        prop1: 5,
        obj2: {
          prop1: [3, 6, 3],
          prop2: 74,
          4_3: {
            str: "Hello World"
          },
        }
      };
      
console.log(obj.obj2['43'].str);

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