Object.hasOwn Javascript

const BRAND_MARKET_SHARE_MAPPING = {
  'Brand A': 0, // Market share is 0%
  'Brand B': 4.3,
};

const brand = { name: 'Brand A' };

// Using direct access:
BRAND_MARKET_SHARE_MAPPING[brand.name] && {
  label: 'Market Share',
  value: '0%',
}; 
// This will not include the object because 0 is falsy.

// Using Object.hasOwn:
Object.hasOwn(BRAND_MARKET_SHARE_MAPPING, brand.name) && {
  label: 'Market Share',
  value: '0%',
};
// This will correctly include the object because the property exists.

Resources