Another option would be to use Array.some
(if available) in the following way:
Array.prototype.contains = function(obj) {
return this.some( function(e){ return e === obj } );
}
The anonymous function passed to Array.some
will return true
if and only if there is an element in the array that is identical to obj
. Absent such an element, the function will not return true
for any of the elements of the array, so Array.some
will return false
as well.