On Friday 19 January 2007 16:46, Kjell Bublitz wrote:
Hii 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
include() does this Cheers, Dave -- ---------------------- Author Ajax in Action http://manning.com/crane Ajax in Practice http://manning.com/crane2 Prototype & Scriptaculous Quickly http://manning.com/crane3 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
