I want to cast all object fields to boolean.
function parseBooleanObject (obj) {
const flagKeys = Object.keys(obj)
return flagKeys.reduce(
(newFlags, key) => (newFlags[key] = obj[key] === 'true'), {}
)
}
const obj = { showVideo: 'true', isStudent: 'false' }
const parsedObj = parseBooleanObject(obj)
console.log('parsedObj: ', parsedObj)
But this code returns false
instead of parsing fields to boolean
{ showVideo: true, isStudent: false }