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

133
Views
Convert comma seperated values into object specified method

Hi I am trying to achieve following behaviors with javascript

let fieldsArray = ['clientMap', 0, 'legalEntityNumber']

somehow I want to get convert above data into following way

['clientMap'][0]['legalEntityNumber']

I tried with fieldsArray.join('[]') but its not working as expected. please help. Thanks

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

0

This will do assuming you intended to convert the items to array of arrays (Type: (string|number)[][])

let fieldsArrayArray = ['clientMap', 0, 'legalEntityNumber'].map(item=>[item])

Basically mapping each element of the array outputting single item array.

If the output should be string then for some reason (Type: string)

let fieldsArrayStringArrays = ['clientMap', 0, 'legalEntityNumber'].map(item=>`[${item}]`).join("")
about 4 years ago · Juan Pablo Isaza Report

0

If im understanding you correctly (and you want a string i.e. "[clientMap][0][legalEntityNumber]") this would be how to do that...

let fieldsArrayString = ['clientMap', 0, 'legalEntityNumber'].map(item=>`[${item}]`).join('');

or

let fieldsArrayString = ['clientMap', 0, 'legalEntityNumber'].reduce((acc, cur) => `${acc}[${cur}]`, '');
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!