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

108
Views
accessing object property dynamically from array of strings

I am trying to access an object property dynamically from an array of strings (the have the path of the needed value)! it seems it access only the first index(Properties) but the others in undefine I am expecting the result to be "ES_STUE".

let objPath = ["properties.Constraints.Level"];

const object = {
  properties: {
    Visibility: {
      "Tender Code": "",
    },
    Data: {
      DTU_ClassificationNumber: "",
      DTU_InformationAccuracy: "",
    },
    "Model Properties": {
      "Workset (Manual)": "No",
    },
    Constraints: {
      Level: "ES_STUE",
      Host: "Level : ES_STUE",
      "Offset from Host": "0.000 mm",
      "Moves With Nearby Elements": "No",
      "Default Elevation": "0.000 mm",
    },
  },
};

for (const iterator of objPath) {
  const keySigment = iterator.split(".");
  for (const prop of keySigment) {
    console.log(prop);
    const result = object[prop];
    //const result = object["Properties"]["Constraints"]["level"]  not sure if this is correct
    console.log(result); // the result should be "ES_STUE"
  }
}

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

0

Logic

  • Split the objPath string.
  • Loop through the split array
  • Each time while looping update the result node with result[prop] where prop is the key.
  • This will drill down the object as itration.

let objPath = ["properties.Constraints.Level"];

const object = {
  properties: {
    Visibility: {
      "Tender Code": "",
    },
    Data: {
      DTU_ClassificationNumber: "",
      DTU_InformationAccuracy: "",
    },
    "Model Properties": {
      "Workset (Manual)": "No",
    },
    Constraints: {
      Level: "ES_STUE",
      Host: "Level : ES_STUE",
      "Offset from Host": "0.000 mm",
      "Moves With Nearby Elements": "No",
      "Default Elevation": "0.000 mm",
    },
  },
};

for (const iterator of objPath) {
  const keySigment = iterator.split(".");
  let result = object;
  for (const prop of keySigment) {
    console.log(prop);
    result = result[prop];
    console.log(result); // the result should be "ES_STUE"
  }
}

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!