Is there a way to upper-case all keys of an object using map
or reduce
so the result may be returned directly?
It works fine with forEach
var o = {
fname: 'john',
lname: 'doe'
}
var result = {}
Object.entries(o)
.forEach((el) => {
result[el[0].toUpperCase()] = el[1]
})
console.log('result', result) // works
But trying to change to
reduce
is not working
var o = {
fname: 'john',
lname: 'doe'
}
var result = Object
.entries(o)
.reduce((accum, curr) => {
return accum[curr[0].toUpperCase()] = curr[1]
}, {})
console.log('result', result)