Regarding this discussion on JavaScript string concatenation behavior with null or undefined values: Link
I have been attempting to render an array composed of an infinite number of arrays of objects, some of which may be undefined. I am seeking a more elegant approach to address this issue as my current solution lacks professionalism.
const theFunction = () => {
let EveryArrayGoesHere = []
try {
EveryArrayGoesHere = EveryArrayGoesHere.concat(array1, array2, array3 ...)
if (EveryArrayGoesHere) {
EveryArrayGoesHere = JSON.stringify(EveryArrayGoesHere)
EveryArrayGoesHere = EveryArrayGoesHere.replace('null,', '')
EveryArrayGoesHere = EveryArrayGoesHere.replace(',null', '')
return JSON.parse(EveryArrayGoesHere);
} else {
return 'data not available';
}
} catch (e) {
if (e) {
console.error('data error', e.message)
}
}
}
console.log('array of objects:',theFunction() )