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

106
Views
Convert JSON string to Object or array

Data from previous result to be used as input and change that to a format I can make use to query my following actions.

The JSON String received is: Example:

var a = apple,car,earth
var b = fruit,vehicle,planet

Desired final output in Array : when apple is queried it should list fruit when car is queried it should list vehicle when earth is queried it should list planet

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

0

I hope this is what you are looking for...

var a = 'apple,car,earth'
var b = 'fruit,vehicle,planet'
a = a.split(',')
b = b.split(',')

d = {}

for (var i = 0; i < a.length; i++)
    d[a[i]] = b[i];

console.log(d['apple'])
console.log(d['car'])
console.log(d['earth'])

about 4 years ago · Juan Pablo Isaza Report

0

It should be straightforward using "Map".

let a = 'apple,car,earth'.split(',');
let b = 'fruit,vehicle,planet'.split(',');
const MapOfItems = new Map();
a.forEach((item, index) => MapOfItems.set(item, b[index]));
console.log(`\nobj`, MapOfItems);
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!