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

230
Visualizações
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 à 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