I want to loop an array to create an object.
input:
const input = [{email:email1, name: name1},{email:email2, name: name2}, {email:email3, name: name3}]
Desired output:
const output = {email1: name1, email2: name2, email3: name3
}
In javascript, I wrote
let output = input.reduce((acc, cur, i) => {
return (acc[cur.email] = cur.name)
}, {})
But I got a typing error saying obj cannot have a string property. How should I type this function properly?
emailXandnameXvariables? If not then they are undefined when reading the value.