I have the following:
let keys = ['a','b','c'];
let vals = ['1','b','h'];
const my_obj = keys.reduce(function(acc,key,i) {
return acc[key]=vals[i];
},{});
logger.log(my_obj);
I would like my_obj to be {a:1,b:b,c:h}.
I'm getting:
TypeError: Cannot create property 'b' on string '1'
at Array.reduce
What am I doing wrong?
Object.fromEntries(keys.map((val,i)=>[val,vals[i]]))return acc[key]=vals[i];- Replacereturnwithconsole.log()and check the output