Skip to content

Instantly share code, notes, and snippets.

@code2be
Created October 5, 2015 13:19
Show Gist options
  • Save code2be/5c18b1e98668203da840 to your computer and use it in GitHub Desktop.
Save code2be/5c18b1e98668203da840 to your computer and use it in GitHub Desktop.
JS Array's indexOfRegex
var x = ['one', 'two', 'three'];
Array.prototype.indexOfRegex = function(regex) {
for(var i=0; i < this.length; i++) {
if(this[i].search(regex) > -1)
return i;
}
return -1;
}
console.log(x.indexOfRegex(/n/));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment