Reputation: 2205
I use the react Dropzone to select files and I wanted to exclude files that don't have a file extension.
I select files with Dropzone and scanning them if they have a file extending or not like
I try various things like
return filename.split('.').pop();
That returns the filename if there is no file extension and if there is a file extension it returns the extension like "exe" or "png".
But how to know if there is no extension on the Dropzone selected file?
E.g. files with extensions
file.png
file.exe
file.text
E.g. files with no extensions
file
file
file
Upvotes: 0
Views: 317
Reputation: 311498
You could check the length of the splitted array, e.g.:
var splitted = return filename.split('.');
return splitted.length > 1 ? splitted.pop() : null;
Upvotes: 2