Removes specific item from Array


/ Published in: ActionScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. // Creates Array
  2. var myArray:Array = ["item1", "item2", "item3", "item4", "item5"];
  3.  
  4. // Function
  5. function removeItemFromArray( item:String ):Void
  6. {
  7. trace("Array Original: " + myArray);
  8.  
  9. // Array Lenght
  10. var arrayLenght:Number = myArray.length;
  11.  
  12. // Searches item in array
  13. for ( i =0; i<arrayLenght; i++ )
  14. {
  15. // Finds item and removes it
  16. if ( myArray[i] == item )
  17. {
  18. myArray.splice( i, 1 );
  19. trace("Item Removed: " + myArray[i] + newline);
  20. trace("Array Updated: " + myArray);
  21. }
  22. }
  23. }
  24.  
  25. // Calls Function
  26. removeItemFromArray( "item3" );

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.