метод (reduce)
const getZippedArrays = (keyArr, valArr) =>
keyArr.reduce((obj, key, i) => {
obj[key] = valArr[i]
return obj
}, {})
метод (reduce)
const getZippedArrays = (keyArr, valArr) =>
keyArr.reduce((obj, key, i) => {
obj[key] = valArr[i]
return obj
}, {})
Простой и понятный способ
let getZippedArrays = function (keys, values) {
let result = {};
for (let i = 0; i < keys.length; i++) {
result[keys[i]] = values[i];
}
return result;
}
Чуть сложнее и менее понятно через Object.assign()
function getZippedArrays(keys, values) {
return Object.assign({}, ...keys.map((key, i) => ({[key]: values[i]})));
}
и через array.reduce()
function getZippedArrays(keys, values) {
return keys.reduce((obj, key, i) => ({...obj, [key]: values[i]}), {});
}
let getZippedArrays = function (keyNames, valueNames){
let array = {};
for (let i = 0; i < keyNames.length; i++){
array[keyNames[i]] = valueNames[i];
}
return array;
}