title: React Javascript, find in a array undefined and skip it
body: <p>I have an array of objects</p>
  <pre><code>const contentTypes = [
      {
          &quot;contentType&quot;: {
              &quot;content_type_id&quot;: 2,
              &quot;content_type&quot;: &quot;image&quot;,
          },
      },
      {
          &quot;contentType&quot;: {
              &quot;content_type_id&quot;: 3,
              &quot;content_type&quot;: &quot;video&quot;,
          },
      },
      {
          &quot;contentType&quot;: {
              &quot;content_type_id&quot;: 1,
              &quot;content_type&quot;: &quot;audio&quot;,
          },
      },
  ]
  </code></pre>
  <p>This is my function <code>setType</code>, where I find any element and set the <code>content_type_id</code> to <code>content_type</code>. I convert the value in a string</p>
  <pre><code>const setType = (selectedType) =&gt; {
      _setType(selectedType)
      const typeString = contentTypes.find((item) =&gt; {
          return item.contentType.content_type_id === selectedType
      }).contentType.content_type;
      onTypeChange(typeString)
  }
  </code></pre>
  <p>My problem is that I also have an element in the array <code>contentTypes</code> without the <code>content_type_id</code> and <code>content_type</code> so I get this error</p>
  <p><strong>Unhandled Runtime Error
  TypeError: Cannot read property 'contentType' of undefined</strong></p>
  <p>This is a jsFiddle =&gt; <a href="https://jsfiddle.net/9x426Lv7/2/" rel="nofollow noreferrer">https://jsfiddle.net/9x426Lv7/2/</a></p>
  <p>How can I skip this element in the find method? Is there a better way to do this?</p>