Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

224
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!