Skip to content

Instantly share code, notes, and snippets.

@ourmaninamsterdam
Last active December 16, 2015 03:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ourmaninamsterdam/5370671 to your computer and use it in GitHub Desktop.
Save ourmaninamsterdam/5370671 to your computer and use it in GitHub Desktop.
Filters an array based on filter. Accepts regex or simple string. Returns a filtered array.
var filter = '.png';
var list = ['userimage105325.png','userimage669.jpg','userimage6929.png','userimage85818.gif'];
function filterArray(array, filter){
var i, filteredArray = [];
filter = new RegExp(filter, 'g');
for( i = 0, len = array.length; i < len; i++ ){
if( array[i].toString().match(filter) ){
filteredArray.push( array[i] );
}
}
return filteredArray;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment