0

I have a javascript object like this, let's call it store:

{
  area1: {my product name: 'red'}
}

I want to check if a specific value exists in store, using hasOwnProperty. Assuming that I have all these values already defined in properties, like area, productName and color, how can I check if store has a area property ans this one also has a productName property?

I basically would like to do something like

const res = store.hasOwnProperty(area[productName]) && store[area][productName]=== color;

which seems not to work.

user3174311
  • 1,714
  • 5
  • 28
  • 66
  • Is `area` a string or an object? `area[productName]` means it's an object but `store[area][productName]` doesn't make sense – Hao Wu Jan 13 '23 at 09:25
  • 1
    What you want might be `const res = store[area]?.[productName] === color` – Hao Wu Jan 13 '23 at 09:27

0 Answers0