Below code is converting object into {"a":"1","b":"2","c":"3","d":"4","e":"5"}, in reduce it is looping through the array and generates the desired output. But then reduce throws TypeError : undefined is not a function.
I have gone through many links but those are not the solution for my error.
Any type of help is welcome.
Please check the code snippet below
let a= {
"a": ["1", "2"],
"b": ["2", "2"],
"c": ["3", "2"],
"d": ["4", "2"],
"e": ["5", "2"]
}
const b= Object.assign(...Object.entries(a).map(value => value.map((value1, index) => index == 0 ? value1 : value1[0])).reduce((a, c) => {
//console.log('c', c);
a[c[0]] = c[1];
console.log(a);
return a;
}, {}));
b?{"a":"1","b":"2","c":"3","d":"4","e":"5"}.