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

134
Vistas
Why does accessing with the member access operator throw error

In the following example we are accessing properties of an object but why does accessing the object with the Member Access throw an error:

 var d = {a: 10, b: 20, c:30};
         
         var keys = Object.getOwnPropertyNames(d);
         
         for(let i = 0; i < keys.length; i++){
            console.log(d[keys[i]]);
            //console.log(d.keys[i]); //throws error
         }

For example shown above, I would assume this would be because if we accessed it with the member access operator it would try to access d immediately without initializing keys[i]. Would this be correct?

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

0

At first, d.keys is tried to be accessed and find item at index i. See what happens if there is an item inside d named as keys:

var d = {
  a: 10,
  b: 20,
  c: 30,
  keys: [1, 2, 3, 4]
};

var keys = Object.getOwnPropertyNames(d);

for (let i = 0; i < keys.length; i++) {
  // console.log(d[keys[i]]);
  console.log(d.keys[i]); //works if finds any property named keys
}

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