I think, the key is in not fighting the complexity in-place, but rather move it out.
If the language does not provide a construction you need, you can try using a library (like lodash; I'm not sure if it has what you need).
If you don't want to use any third-party dependencies, you can still home brew the missing thing. It can be as simple as an importable isolated function:
function replaceObjectNullFields(source, nullReplaceValue = false) {
return Object
.keys(source)
.reduce(
(subResult, key) => (
subResult[key] = source[key] != null ? source[key] : nullReplaceValue,
subResult
),
{}
);
}
Then you don't have the nasty proliferation of the micro-level details across the code base. It's nasty because it forces us mixing the abstractions of different levels...
With the function above you can rewrite the code into a one-liner, because the complexity is encapsulated somewhere else
objL[0] = replaceObjectNullFields(objL[0])
Alternatively, you could write a more generalized mapObject()
function with a signature similar to what @Pavlo demonstrated in his good answer.
objL[0] = Object.entries(objL[0]).reduce((result, [key, value]) => { result[key] = value != null ? value : false; return result; }, {})
\$\endgroup\$