You can remove all “falsy” values from an Array by filtering for Boolean.
const fruits = [
'Apple',
null,
'PineApple',
undefined,
'CustardApple',
undefined,
'GoldenApple'
]
const filteredFruits = fruits.filter(Boolean)
filteredFruits // ["Apple", "PineApple", "CustardApple", "GoldenApple"]