Posted By

Meestercor on 01/22/09


Tagged

textmate search array


Versions (?)

array search


 / Published in: Other
 

  1. function array_search(needle:String, haystack:Array):Number {
  2. var i:Number;
  3. var found:Boolean = false;
  4. for (i=0; i<haystack.length; i++) {
  5. if (haystack[i] == needle) {
  6. found = true;
  7. break;
  8. }
  9. }
  10. if (found == true) {
  11. return (i);
  12. } else {
  13. return (-1);
  14. }
  15. }
  16.  
  17. function searchArray():Void{
  18. var arrayIndex:Number = array_search(mc, inputArray);
  19. if (arrayIndex != -1) {
  20. // do something
  21. } else {
  22. //trace("Not In Array");
  23. }
  24. }

Report this snippet  

You need to login to post a comment.