//ensure that these arrays are not undefined before calling the flatMap method.
const intervals = Array.from(new Set(products?.flatMap(product => product?.prices?.map(price => price?.interval))))
// To prevent error(undefined (reading 'length')),
!products || products.length === 0
//ensure that these arrays are not undefined before calling the flatMap method. const intervals = Array.from(new Set(products?.flatMap(product => product?.prices?.map(price => price?.interval)))) // To prevent error(undefined (reading 'length')), !products || products.length === 0