Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save Octagon-simon/5668ee9f53380e4aa83407344c5ef46e to your computer and use it in GitHub Desktop.
//create an array that will store the image file type
const requiredTypes = ["image/jpg", "image/jpeg", "image/png"];
//store error
const valError = [];
//loop through object and compare type
for (let file of fileInpFiles){
if ( !requiredTypes.includes( file.type ) ){
valError.push(file.name);
}
}
//check if there's a validation error
if( valError.length !== 0 ){
valError.forEach( f => {
console.log(`${f} is not an image file`);
} );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment