Last active
August 29, 2015 13:56
-
-
Save bradoyler/9162129 to your computer and use it in GitHub Desktop.
JS console lesson : array filtering
This file contains 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
// filter words with a RegEx | |
var startsWithA = new RegExp(/^a/i); // filter by first letter A | |
var arr = ['Apple','avocado','Banana','Cherry']; | |
var filtered = arr.filter(function(item){ | |
return startsWithA.test(item); | |
}); | |
var nonAlpha = new RegExp('[^a-zA-Z\d\s:]'); // filter non-Alpha chars | |
var arr2 = ['Apple','avocado','Banana','Cherry']; | |
var filtered2 = arr.filter(function(item){ | |
return !nonAlpha.test(item); | |
}); | |
console.log(filtered2); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment