Posted By

withinmedianl on 04/04/11


Tagged

new unique


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

doctorstones


Check if item is not already in an Array


 / Published in: ActionScript 3
 

Based upon another snippet from this site, but can't remember where i got it

  1. private function isNewInArray(value:Object, arr:Array):Boolean
  2. {
  3. for (var i:uint=0; i < arr.length; i++)
  4. {
  5. if (arr[i]==value)
  6. {
  7. return false;
  8. }
  9. }
  10. return true;
  11. }
  12.  
  13. if(isNewInArray(foo, barArray))
  14. {
  15. barArray.push(foo);
  16. }
  17. else
  18. {
  19. trace("Item already in array");
  20. }

Report this snippet  

You need to login to post a comment.