ok yours is better, you win :)
On 1/19/07, Thomas Fuchs <[EMAIL PROTECTED]> wrote:
['a','b','c'].include('b') --> true
See http://prototypejs.org/api/enumerable/include
Best,
Thomas
Am 19.01.2007 um 17:46 schrieb Kjell Bublitz:
>
> 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
>
> >
>
--
DCRails.com || Making the Metrorail fun!
http://www.captureimportant.info || Sidewalk || Bring People to You
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---