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

99
Views
How do i access an object's key but i want to pass the key as a variable

for example:

object = {
  name: "Mike",
  age: 15
}

object.age // returns 15 right?

But I want to pass the 'age' key as a variable name:

object = {
  name: "Mike",
  age: 15
}

const age = 10.toString()

How do I get the result of something like this:

object.`${age}`
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Try

object["age"]

or

var propName='age'
object[propName]
about 4 years ago · Santiago Trujillo Report

0

You can simply do this by

object[age]
about 4 years ago · Santiago Trujillo Report

0

Properties can be accessed by either . (dot notation) or via brackets [] that is:

object[key_name]
// where key_name is a variable
object["some_key"] // {"some_key":"value"} or {some_value:"value"}
object[19] // {19:"some_value"}
about 4 years ago · Santiago Trujillo Report
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!