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

112
Views
How to access dynamic key values in nested objects

This is my JSON file:

{
 "Key": "some-key",
        "some-key": {
        "comLength": 1
        },
}

How do I access the comLength value?

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

I would do this

  1. parse to custom object
  2. do a For-loop by the required property
  3. break the loop as soon I found the match
about 4 years ago · Juan Pablo Isaza Report

0

Considering your object variable is named someObject, you can access it like:

var comLength = someObject["some-key"].comLength

Example:

var someObject = {
     "Key": "some-key",
     "some-key": {
        "comLength": 1
     },
}

var comLength = someObject["some-key"].comLength;

console.log(comLength);

about 4 years ago · Juan Pablo Isaza Report

0

You can reference it via the dot notation (.) and the square notation ([]) (the [] notation is mandatory in case of the property key of some-key because of the -)

const obj = {
    "Key": "some-key",
    "some-key": {
            "comLength": 1
        }
};


console.log(obj["some-key"].comLength);
console.log(obj["some-key"]["comLength"]);

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