const keys = ['key1', 'key2', 'key3'];
const values = ['value1', 'value2', 'value3', 'value4', 'valu5', 'value6'];
const makeGen = function*(arr) {
let index = 0;
const { length } = arr;
while (true) {
yield arr[index++ % length];
}
}
const keyGen = makeGen(keys);
const valGen = makeGen(values);
const length = Math.max(keys.length, values.length);
const result = Array.from({ length }, () => [keyGen.next().value, valGen.next().value]);
console.log(JSON.stringify(result, null, 2));
/*
[
[
"key1",
"value1"
],
[
"key2",
"value2"
],
[
"key3",
"value3"
],
[
"key1",
"value4"
],
[
"key2",
"valu5"
],
[
"key3",
"value6"
]
]
*/