title: How to check file extension using React
body: <p>I want to check whether the file extension is an image or a pdf file. But using my code, only else part is working.</p>
  <pre><code> const thumbs = files.map((selectedFile) =&gt; (
      &lt;div key={selectedFile[&quot;name&quot;]} className=&quot;d-flex&quot;&gt;
        {selectedFile['.type'] == &quot;.pdf&quot; ? (
          &lt;iframe src={selectedFile[&quot;preview&quot;]} style={{ height: &quot;20%&quot;, width: &quot;20%&quot; }} /&gt;
        ) : (
          &lt;img
            src={selectedFile[&quot;preview&quot;]}
            alt={selectedFile[&quot;name&quot;]}
            style={{ height: &quot;20%&quot;, width: &quot;20%&quot; }}
          /&gt;
        )}
      &lt;/div&gt;
    ));
  </code></pre>