Skip to content

Instantly share code, notes, and snippets.

@floscr
Created August 3, 2016 08:30
Show Gist options
  • Save floscr/9b220579b526b8f3d39d452d4f2fefbc to your computer and use it in GitHub Desktop.
Save floscr/9b220579b526b8f3d39d452d4f2fefbc to your computer and use it in GitHub Desktop.
Filter images from an array of files
// Test file list
let fileList = [
'myFile.js',
'myImage.png',
'./subdir/image.jpg',
];
// Filter images from the changed files list
let imageFiles = fileList.filter(fileName => {
return fileName.match(/\.(jpg|png|gif)$/);
});
// -> ['myImage.png', './subdir/image.jpg',]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment