Hi

i was wondering if there is a quick way to search for a item within an
array. Here is my approach for this functionality. It's an prototype
for an Array method called "has":

Array.prototype.has = function(needle) {
        for (var i=0;i<this.length;i++) {
                if(this[i] == needle){ return true; }
        }
        return false;
}

var someArray = ['jim', 'marge', 'timmeh', 'bob'];

if( someArray.has('bob') )
{
   alert('found bob')
}

Isn't there something like "has()" in prototype already? I have seen
the find / findAll, but the example in the docs are kinda complex for
"just that".. could someone break it down for me please? i would much
appreciate.

TIA, Kjell

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on 
Rails: Spinoffs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to