Guy Watson: Array.prototype.in_array=function(value){ for(var z=0;z<this.length;++z){ if(this[z] == value){ return true } } return false }
Also found this @ layer51.com/proto: msg3 { *k-zimir* [+] <http://www.layer51.com/proto/up.aspx?u=k-zimir>, posted: 10.22.02 9a•-, top [^] <http://www.layer51.com/proto/d.aspx?f=6#> } except using a while loop, this returns the position if found and -1 if not.. might be little handsomer sometimes. Array.prototype.in_array=function(value){ var l; l = this.length; while(l--) { if(this[l] == value){ return l; } } return -1; } Of course you could rewrite the above to make them AS2. There are tons of Array prototypes to be found there. (www.layer51.com/proto) edolecki On 12/16/05, GregoryN <[EMAIL PROTECTED]> wrote: > > Hello Flashcoders, > > Sometimes I'd like to use advanced array functions like those in, > say, PHP: in_array (check array for having a value), > array_unique (delete duplicates) etc. > > For now, I use my own ones. Example: > > function my_in_array(needle:String, haystack:Array):Boolean{ > if(haystack.toString().indexOf(needle) == -1){ > return true; > }else{ > return false; > } > } > > Frankly, I'm not sure if this is the best/fastest way for such > tasks: "needle" needs to be a string type. > > Does anyone have info or ideas on this? > > > -- > Best regards, > GregoryN > ================================ > http://GOusable.com > Flash components development. > Usability services. > > > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders >
_______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders