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

111
Views
Is there a way to update a deeply nested value of this structure via recursive method

I am attempting to update this array of objects based on the object key. Each key maps to a registry which holds a method to format the data and return it and then update the object key. This recursive function works but cant handle an object key which has a nested object.

 [
  {
    "myData": "test",
    "nestedArr": [
      {
        "hello": "test",
        "check": "test",
        "nestedObject": {
          "hello": "hello",
          "nestedArr": [
            {
              "test": {
                "value": "updateMe"
              }
            }
          ]
        }
      }
    ]
  }
]

Here is my current implementation

const parse = async (arr) => {
  return await Promise.all(
    arr.map(async (obj) => {
      await Promise.all(
        Object.keys(obj).map(async (value) => {
          if (Array.isArray(obj[value])) {
            await parse(obj[value]);
          }

          try {
            const method = registry[value];
            const data = await method(obj, value);
            obj[value] = data;
          } catch (error) {}
        })
      );

      return obj;
    })
  );
};

UPDATED:

const parse = async (arr) => {
  return await Promise.all(
    arr.map(async (obj) => {
      await Promise.all(
        Object.keys(obj).map(async (value) => {
          if (Array.isArray(obj[value])) {
            await parse(obj[value]);
          }

          try {
            if (typeof obj[value] === "object") {
              await parse([obj[value]]);
            }
          } catch (error) {}

          try {
            const method = registry[value];
            const data = await method(obj, value);
            obj[value] = data;
          } catch (error) {}
          
        })

      );

      return obj;
    })
  );
};
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

@Barmar pointed me in the right direction, updated the result. Works great not too concerned on the performance aspect as this result will be cached in redis

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!