Error when trying to return object array

I am iterating over an object to output a list of product names in my search results:

${ => product.productName)}

However not every record has has this object and so I am seeing an error in the console

“Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘map’)”

and the search results are not showing.

How can I skip the attempted output if the object doesn’t exist?


Sorry this is a duplicate of How to stop error when using menu