Remove elements from an associative array


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



Copy this code and paste it in your HTML
  1. /**
  2.  *
  3.  * @param $obj The object you want to delete elements from
  4.  * @param parameters A comma delimeter parameters to be passed on the object for deletion, if a parameter is not found the object it will be skipped
  5.  * @return The new object with the deleted element
  6.  *
  7.  */
  8. public static function deleteElements ($obj:Object, ...parameters):Object {
  9.  
  10. if ($obj != {} || $obj != null) {
  11. for (var s:String in parameters) {
  12. if ($obj[parameters[s]] && $obj[parameters[s]] != undefined) {
  13. $obj[parameters[s]] = null;
  14. delete $obj[parameters[s]];
  15. } else {
  16. trace ("parameter,", parameters[s], "was skipped as it couldn't be found on the object");
  17. }
  18. }
  19. }
  20.  
  21. return $obj;
  22. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.