Thursday, November 17, 2005

test if array contains...

JavaScript has no built in way to test if an item exists (as a value) in an Array/Object. Here's a handy prototype I whipped up.

Array.prototype.Contains = function(mxd,strict) {
for(i in this) {
if(this[i] == mxd && !strict) return true;
else if(this[i] === mxd) return true;
return false;

// i.e.
if(arrMy.Contains("it")) alert("We have it!");

This could be useful to see if someone has priverlages or whatever...


Post a Comment

<< Home

My status