Skip to content

Instantly share code, notes, and snippets.

@Octagon-simon
Created July 15, 2022 16:26
Show Gist options
  • Select an option

  • Save Octagon-simon/30c310329d11af857487fb5829d0d415 to your computer and use it in GitHub Desktop.

Select an option

Save Octagon-simon/30c310329d11af857487fb5829d0d415 to your computer and use it in GitHub Desktop.
//store required extensions
const requiredExts = [".png", ".jpg", ".jpeg"];
//store error
const valError = [];
//loop through object
for (let file of fileInpFiles){
//retrieve extension from name
const ext = file.name.substring(file.name.lastIndexOf('.'));
//check if it matches with the required extension
if ( !requiredExts.includes( ext ) ){
//store file name that doesn't match the extension
valError.push( file.name );
}
}
//check if there's a validation error
if( valError.length !== 0 ){
valError.forEach( f => {
console.log(`${f} is not supported`);
} );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment