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

233
Vistas
React JS access object attribute using "." and variable

today at work a friend show me a strange way to access an object attribute using a variable.

To make it simple to understand, first we define an object, then a variable with a key of this object as string, then we try to access this key on the object.

object = {"123": 1, "12":2}
key = "12"
console.log(object[key])

this would return 2 and is the right way to do.

So my friend was doing this on react

object = {"123": 1, "12":2}
key = "12"
console.log(object.[key])

Trying this code on webbrowser console, returns error, but on React it works.

Can someone tell me why???? I'm really curious to know why this no sense code works

ready snippet to try on pure js

https://jsfiddle.net/ozgvfw02/1/

about 4 years ago · Juan Pablo Isaza
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