title: How can i use .map() only when there is an array?
body: <p>I am new to react and I am passing an item prop. Some of the items has an empty array in items.modifiers. When I use an if an if condition i still get an error that &quot;Cannot read property 'map' of undefined &quot; Below is my code. Any help would be really appreciated.</p>
  <pre><code>const NewModal = ({ item }) =&gt; {
    if (item.modifiers !== &quot;&quot;) {
      item.modifiers.map((modifier) =&gt; console.log(modifier.cat_name));
    }
  };
  
  return [
    {
      items: [
        {
          item_id: 1,
          item_name: &quot;Philadelphia Steak Sandwich&quot;,
  
          modifiers: {
            cat_name: &quot; Choose a side&quot;,
            mod_items: [
              { mod_item_name: &quot;French Fries&quot;, price: 1 },
              { mod_item_name: &quot;Cole Slaw&quot;, price: 2 },
            ],
          },
        },
        {
          item_id: 2,
          item_name: &quot;Philadelphia Steak Sandwich Deluxe&quot;,
  
          modifiers: &quot;&quot;,
        },
      ],
    },
  ];
  
  </code></pre>