I am looking to transform an object by replacing any falsey values with "All" and then converting the object into a single string. Initially, I attempted using the .reduce
method, which successfully replaces falsey values. However, I am struggling to find an elegant solution to format the object such that each key-value pair is separated by commas within the same string.
const object1 = {
a: 'somestring',
b: 42,
c: false,
d: null,
e: 0,
f: "Some"
};
let newObj = Object.keys(object1).reduce((acc, key) => {
if(!object1[key]){
object1[key] = "All"
}
return {...acc, [key]: object1[key]}
}, {})
console.log(Object.entries(newObj).join(":"));
My desired output should be
"a: somestring, b: 42, c: All, d: All, e: All, f: Some"