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

160
Views
Dynamically access complex javascript object property value

I have the following JavaScript / Typescript object:

data = {
  customer: {
    id: 1,
    name: "X",
    address: {
      line1: "address line 1",
      line2: "address line 2",
      country: {
        code: "US",
        name: "United States"
      }
    }
  }
};

I would like to dynamically access specific property value. Example: data.customer.address.country.code should return "US".

I am able to dynamically set the last property in the object hierarchy.

console.log(data.customer.address.country["code"]) // This works

Is there anyway I access any property in the object dynamically?

I tried:

console.log(data["customer.address.country.code"]) // Does not work

console.log(data["customer.id"]) // Does not work

Code Snippet:

data = {
  customer: {
    id: 1,
    name: "X",
    address: {
      line1: "address line 1",
      line2: "address line 2",
      country: {
        code: "US",
        name: "United States"
      }
    }
  }
};

console.log(data.customer.address.country["code"]) // This works

console.log(data["customer.address.country.code"]) // Does not work

console.log(data["customer.id"]) // Does not work

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!