* def alphabets = ["a","b","c"]
* def number = ["1","2","3"]
So that the final mapped result should be
final =[{"a":"1"},{"b":2""},{"c":"3"}]
* def alphabets = ["a","b","c"]
* def number = ["1","2","3"]
So that the final mapped result should be
final =[{"a":"1"},{"b":2""},{"c":"3"}]
Try this Array reduce
function. It should give the expected result.
alphabets.reduce((mem, alphabet, index) => {
mem.push({[alphabet]: number[index]});
return mem;
}, []);
var alphabets = ["a","b","c"]
var number = ["1","2","3"]
res=alphabets.map((e,i)=>({[e]:number[i]}))
console.log(res)
Here you go. Next time maybe you shouldn't tag your question as JS / JSON ;)
* def fun = function(x, i){ var pair = {}; pair[x] = number[i]; return pair }
* def pairs = karate.map(alphabets, fun)