如何在空手道中对两个数组进行一对一映射
How to do one to one mapping of two arrays in karate
* def alphabets = ["a","b","c"]
* def number = ["1","2","3"]
所以最终的映射结果应该是
final =[{"a":"1"},{"b":2""},{"c":"3"}]
试试这个数组 reduce
函数。它应该给出预期的结果。
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)
给你。下次也许你不应该将你的问题标记为 JS / JSON ;)
* def fun = function(x, i){ var pair = {}; pair[x] = number[i]; return pair }
* def pairs = karate.map(alphabets, fun)
* def alphabets = ["a","b","c"]
* def number = ["1","2","3"]
所以最终的映射结果应该是
final =[{"a":"1"},{"b":2""},{"c":"3"}]
试试这个数组 reduce
函数。它应该给出预期的结果。
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)
给你。下次也许你不应该将你的问题标记为 JS / JSON ;)
* def fun = function(x, i){ var pair = {}; pair[x] = number[i]; return pair }
* def pairs = karate.map(alphabets, fun)