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
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'])
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);