Nate Woods

Nate Woods

JavaScript Array Contains

2013-03-18

Here is a quick one for you today.  Ever just want a simple way to see if there is an item in an array?  Well fear not, this little snippet is to the rescue!

Array.prototype.contains = function(x) {
    return (this.indexOf(x) > -1);
}

Hope this helps with any containment needs!

×