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

147
Views
Create a dynamic multilevel array

I want to create JSON using java properties using js.

input

a[1][1]=d

output should be

{ a: [ null, [ null, "d" ] ] }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I found a workaround. first I extract all the indexes and pass it to recursive function

const arrayRecursiveFn = function (indexes, value, result) {
    let index = indexes[0];

    if (indexes.length === 1) {
        result[index] = value;
    } else {
        let obj = [];

        result[index] = arrayRecursiveFn(indexes.slice(1), value, obj);
    }
    return result;
}

const op = arrayRecursiveFn([1,1],0 , [])

console.log("op",op)

full implementation https://github.com/mehimanshupatil/propertiesToJSON

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!