Last active
December 16, 2015 03:29
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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