Get the length of an associative array


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



Copy this code and paste it in your HTML
  1. /**
  2.  * Returns the length of an associative array or object similar function to Array.length
  3.  *
  4.  * @param $obj
  5.  * @return int
  6.  *
  7.  */
  8. public static function __getAssociativeArraySize($obj:Object):int {
  9. var length:int = 0; /* the length counter to be returned */
  10. if ($obj != {} || $obj != null) { /* check if the object is null or has no elements and return zero as the length */
  11. for (var s:String in $obj) { /* iterate on each element of the object and increase the counter */
  12. length++;
  13. }
  14. }
  15.  
  16. return length; /* return the length*/
  17. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.