Recently, I created an inArray function for JavaScript which seems to be working fine. It's short and a bit unusual, but I have a nagging feeling that there might be something wrong with it, although I can't quite pinpoint what it is:
Array.prototype.inArray = function (item) {
return this.join("|").match( new RegExp('\\b'+item+'\\b','ig') );
}
Update: This is meant to serve as a general implementation of the inArray feature. I'm unsure whether a loop or creating a regex is more resource-intensive.